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

samsmithnz / RepoAutomation / 3726343886

pending completion
3726343886

Pull #197

github

GitHub
Merge b94c6a3f2 into 7dccffecf
Pull Request #197: Updated sonar cloud

294 of 428 branches covered (68.69%)

Branch coverage included in aggregate %.

108 of 108 new or added lines in 6 files covered. (100.0%)

708 of 807 relevant lines covered (87.73%)

4.93 hits per line

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

89.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
    {
29✔
10
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
29✔
11
        HttpResponseMessage response = await client.GetAsync(url);
29✔
12
        if (processErrors)
29!
13
        {
×
14
            response.EnsureSuccessStatusCode();
×
15
        }
×
16
        return await response.Content.ReadAsStringAsync();
29✔
17
    }
29✔
18

19
    public async static Task<string?> PostGitHubMessage(string url, string clientId, string clientSecret, StringContent content, bool processErrors = true)
20
    {
1✔
21
        HttpClient client = BuildHttpClient(url, clientId, clientSecret);
1✔
22
        HttpResponseMessage response = await client.PostAsync(url, content);
1✔
23
        if (processErrors)
1✔
24
        {
1✔
25
            response.EnsureSuccessStatusCode();
1✔
26
        }
1✔
27
        return await response.Content.ReadAsStringAsync();
1✔
28
    }
1✔
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
    {
35✔
65
        if (!url.Contains("api.github.com"))
35!
66
        {
×
67
            throw new Exception("api.github.com missing from URL");
×
68
        }
69
        HttpClient client = new();
35✔
70
        client.DefaultRequestHeaders.Accept.Clear();
35✔
71
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
35✔
72
        client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("SamsRepoAutomation", "0.1"));
35✔
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))
35!
75
        {
35✔
76
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", clientId, clientSecret))));
35✔
77
        }
35✔
78
        return client;
35✔
79
    }
35✔
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

© 2025 Coveralls, Inc