• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / RepoAutomation / 4183697105

pending completion
4183697105

push

github

GitHub
Merge pull request #214 from samsmithnz/dependabot/nuget/src/RepoAutomation/GitHubActionsDotNet-1.0.19

330 of 476 branches covered (69.33%)

Branch coverage included in aggregate %.

778 of 903 relevant lines covered (86.16%)

6.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.33
/src/RepoAutomation.Core/APIAccess/BaseApiAccess.cs
1
using System.Net.Http.Headers;
2

3
namespace RepoAutomation.Core.APIAccess;
4

5
public static class BaseApiAccess
6
{
7

8
    public async static Task<string?> GetGitHubMessage(string url, string clientId, string clientSecret, bool processErrors = true)
9
    {
32✔
10
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
32✔
11
        HttpResponseMessage response = await client.GetAsync(url);
32✔
12
        if (processErrors)
32!
13
        {
×
14
            response.EnsureSuccessStatusCode();
×
15
        }
×
16
        return await response.Content.ReadAsStringAsync();
32✔
17
    }
32✔
18

19
    public async static Task<string?> PostGitHubMessage(string url, string clientId, string clientSecret, StringContent content, bool processErrors = true)
20
    {
5✔
21
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
5✔
22
        HttpResponseMessage response = await client.PostAsync(url, content);
5✔
23
        if (processErrors)
5!
24
        {
×
25
            response.EnsureSuccessStatusCode();
×
26
        }
×
27
        return await response.Content.ReadAsStringAsync();
5✔
28
    }
5✔
29

30
    public async static Task<string?> PatchGitHubMessage(string url, string clientId, string clientSecret, StringContent content, bool processErrors = true)
31
    {
1✔
32
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
1✔
33
        HttpResponseMessage response = await client.PatchAsync(url, content);
1✔
34
        if (processErrors)
1✔
35
        {
1✔
36
            response.EnsureSuccessStatusCode();
1✔
37
        }
1✔
38
        return await response.Content.ReadAsStringAsync();
1✔
39
    }
1✔
40

41
    public async static Task<string?> DeleteGitHubMessage(string url, string clientId, string clientSecret, bool processErrors = true)
42
    {
3✔
43
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
3✔
44
        HttpResponseMessage response = await client.DeleteAsync(url);
3✔
45
        if (processErrors)
3✔
46
        {
2✔
47
            response.EnsureSuccessStatusCode();
2✔
48
        }
1✔
49
        return await response.Content.ReadAsStringAsync();
2✔
50
    }
2✔
51

52
    public async static Task<string?> PutGitHubMessage(string url, string clientId, string clientSecret, StringContent content, bool processErrors = true)
53
    {
1✔
54
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
1✔
55
        HttpResponseMessage response = await client.PutAsync(url, content);
1✔
56
        if (processErrors)
1✔
57
        {
1✔
58
            response.EnsureSuccessStatusCode();
1✔
59
        }
1✔
60
        return await response.Content.ReadAsStringAsync();
1✔
61
    }
1✔
62

63
    private static HttpClient BuildHttpClient(string url, string clientId, string clientSecret)
64
    {
42✔
65
        if (!url.Contains("api.github.com"))
42!
66
        {
×
67
            throw new Exception("api.github.com missing from URL");
×
68
        }
69
        HttpClient client = new();
42✔
70
        client.DefaultRequestHeaders.Accept.Clear();
42✔
71
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
42✔
72
        client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("SamsRepoAutomation", "0.1"));
42✔
73
        //If we use a id/secret, we significantly increase the rate from 60 requests an hour to 5000. https://developer.github.com/v3/#rate-limiting
74
        if (!string.IsNullOrEmpty(clientId) && !string.IsNullOrEmpty(clientSecret))
42✔
75
        {
41✔
76
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", clientId, clientSecret))));
41✔
77
        }
41✔
78
        return client;
42✔
79
    }
42✔
80

81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc