-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new releases command in public module
- Loading branch information
Showing
8 changed files
with
189 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using PickupBot.GitHub.Models; | ||
|
||
namespace PickupBot.GitHub | ||
{ | ||
public class GitHubService | ||
{ | ||
private readonly HttpClient _client; | ||
|
||
public GitHubService(HttpClient client) | ||
{ | ||
client.BaseAddress = new Uri("https://api.github.com/"); | ||
|
||
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json"); | ||
client.DefaultRequestHeaders.Add("User-Agent", "Discord-Pickup-Bot"); | ||
|
||
_client = client; | ||
} | ||
|
||
public async Task<string> GetCommits(int count = 10) | ||
{ | ||
var response = await _client.GetAsync("/repos/Floydan/discord-pickup-bot/commits"); | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
return await response.Content.ReadAsStringAsync(); | ||
} | ||
|
||
return $"StatusCode: {response.StatusCode}"; | ||
} | ||
|
||
public async Task<IEnumerable<GitHubRelease>> GetReleases(int count = 3) | ||
{ | ||
var response = await _client.GetAsync("/repos/Floydan/discord-pickup-bot/releases"); | ||
|
||
if (!response.IsSuccessStatusCode) return null; | ||
|
||
await using var stream = await response.Content.ReadAsStreamAsync(); | ||
return await JsonSerializer.DeserializeAsync<IEnumerable<GitHubRelease>>(stream); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PickupBot.GitHub.Models | ||
{ | ||
public class GitHubRelease | ||
{ | ||
[JsonPropertyName("author")] | ||
public GitHubAuthor Author { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("body")] | ||
public string Body { get; set; } | ||
|
||
[JsonPropertyName("published_at")] | ||
public DateTime PublishedDate { get; set; } | ||
|
||
[JsonPropertyName("html_url")] | ||
public string Url { get; set; } | ||
} | ||
|
||
public class GitHubAuthor | ||
{ | ||
[JsonPropertyName("login")] | ||
public string Name { get; set; } | ||
[JsonPropertyName("avatar_url")] | ||
public string AvatarUrl { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters