C
C#2y ago
Error101

❔ Octokit can find the git hub repo but not the latest repository

using Microsoft.AspNetCore.Mvc;
using MooMooBotWebAPI.TokenAuthentication;
using System.Net.Http;
using Octokit;
using Serilog;
using System.IO.Compression;
using System.Net;
using Microsoft.TeamFoundation.SourceControl.WebApi.Legacy;

namespace MooMooBotWebAPI.Controllers.api
{
[ApiController]
[Route("/api/webhook")]
public class WebhookController : ControllerBase
{
[HttpPost("test")]
public async Task<IActionResult> Index()
{
string directory = "temp/";

if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

foreach (string file in Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly))
{
if (!new FileInfo(file).Attributes.HasFlag(FileAttributes.Directory))
{
System.IO.File.Delete(file);
}

}
long repoid = 639338237;
//string filepath = Directory.CreateDirectory(Path.Combine("/home", "/discordbot")).FullName;
string filepath = Directory.CreateDirectory(Path.Combine(Values.Directories.Root + "/bot")).FullName;
var client = new GitHubClient(new ProductHeaderValue("MooMoobot9000"));
client.Credentials = new Credentials("token");

var latestRelease = await client.Repository.Release.GetLatest("Error1OH1", "MommyMilkersBotDsharp");
if (latestRelease != null)
{
if (latestRelease.Assets.Count > 0)
{
var assetID = latestRelease.Assets[1].Id;
var asset = await client.Repository.Release.GetAsset("Error1OH1", "MommyMilkersBotDsharp", assetID);
var downloadUrl = asset.BrowserDownloadUrl;

using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("user-agent", "MooMooBot");
httpClient.DefaultRequestHeaders.Add("Authorization", "token " + "toekn");

using (var response = await httpClient.GetAsync(downloadUrl))
{
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsByteArrayAsync();

System.IO.File.WriteAllBytes(filepath + "MooMooBot9000.zip", content);
Log.Information("Successfully downloaded new bot");
}
}
}
else
{
Log.Error("No Assets found in latest release.");
return StatusCode(500, "No assets found");
}

}
else
{
Log.Error("Repository not found.");
return StatusCode(500, "Repository not found");
}

return Ok(new
{
message = "",
time = DateTime.Now.ToString("MM/dd/yyyy - HH:mm:ss.fff"),

});
}
}
}
using Microsoft.AspNetCore.Mvc;
using MooMooBotWebAPI.TokenAuthentication;
using System.Net.Http;
using Octokit;
using Serilog;
using System.IO.Compression;
using System.Net;
using Microsoft.TeamFoundation.SourceControl.WebApi.Legacy;

namespace MooMooBotWebAPI.Controllers.api
{
[ApiController]
[Route("/api/webhook")]
public class WebhookController : ControllerBase
{
[HttpPost("test")]
public async Task<IActionResult> Index()
{
string directory = "temp/";

if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

foreach (string file in Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly))
{
if (!new FileInfo(file).Attributes.HasFlag(FileAttributes.Directory))
{
System.IO.File.Delete(file);
}

}
long repoid = 639338237;
//string filepath = Directory.CreateDirectory(Path.Combine("/home", "/discordbot")).FullName;
string filepath = Directory.CreateDirectory(Path.Combine(Values.Directories.Root + "/bot")).FullName;
var client = new GitHubClient(new ProductHeaderValue("MooMoobot9000"));
client.Credentials = new Credentials("token");

var latestRelease = await client.Repository.Release.GetLatest("Error1OH1", "MommyMilkersBotDsharp");
if (latestRelease != null)
{
if (latestRelease.Assets.Count > 0)
{
var assetID = latestRelease.Assets[1].Id;
var asset = await client.Repository.Release.GetAsset("Error1OH1", "MommyMilkersBotDsharp", assetID);
var downloadUrl = asset.BrowserDownloadUrl;

using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("user-agent", "MooMooBot");
httpClient.DefaultRequestHeaders.Add("Authorization", "token " + "toekn");

using (var response = await httpClient.GetAsync(downloadUrl))
{
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsByteArrayAsync();

System.IO.File.WriteAllBytes(filepath + "MooMooBot9000.zip", content);
Log.Information("Successfully downloaded new bot");
}
}
}
else
{
Log.Error("No Assets found in latest release.");
return StatusCode(500, "No assets found");
}

}
else
{
Log.Error("Repository not found.");
return StatusCode(500, "Repository not found");
}

return Ok(new
{
message = "",
time = DateTime.Now.ToString("MM/dd/yyyy - HH:mm:ss.fff"),

});
}
}
}
2 Replies
Error101
Error101OP2y ago
Does anyone have any idea's what may be causing this, I am having trouble figuring it out with the docs
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server