@@ -29,7 +29,7 @@ public GitHubService(HttpClient httpClient, ILogger logger, string key, string g
29
29
this . key = key ;
30
30
_logger = logger ;
31
31
_httpClient = httpClient ;
32
- githubRoot = $ "https://api.github.com/repos/{ githubRepository } / ";
32
+ githubRoot = $ "https://api.github.com/repos/{ githubRepository } ";
33
33
}
34
34
35
35
/// <summary>
@@ -39,7 +39,7 @@ public GitHubService(HttpClient httpClient, ILogger logger, string key, string g
39
39
/// <returns>A task representing the asynchronous operation, containing a boolean indicating whether the operation was successful.</returns>
40
40
public async Task < bool > CreateCatalogIdentifierAsync ( string catalogIdentifier )
41
41
{
42
- var requestUrl = $ "{ githubRoot } actions/variables";
42
+ var requestUrl = $ "{ githubRoot } / actions/variables";
43
43
var content = new StringContent ( JsonSerializer . Serialize ( new
44
44
{
45
45
name = "catalogIdentifier" ,
@@ -51,7 +51,7 @@ public async Task<bool> CreateCatalogIdentifierAsync(string catalogIdentifier)
51
51
Content = content
52
52
} ;
53
53
request . Headers . Add ( "Authorization" , $ "Bearer { key } ") ;
54
- request . Headers . Add ( "User-Agent" , "HttpClientFactory-Sample " ) ;
54
+ request . Headers . Add ( "User-Agent" , "GitHubToCatalogYaml " ) ;
55
55
56
56
var response = await _httpClient . SendAsync ( request ) ;
57
57
if ( response . IsSuccessStatusCode )
@@ -70,10 +70,10 @@ public async Task<bool> CreateCatalogIdentifierAsync(string catalogIdentifier)
70
70
/// <returns>A task representing the asynchronous operation, containing the catalog identifier as a string, or null if the retrieval fails.</returns>
71
71
public async Task < string > GetCatalogIdentifierAsync ( )
72
72
{
73
- var requestUrl = $ "{ githubRoot } actions/variables/catalogIdentifier";
73
+ var requestUrl = $ "{ githubRoot } / actions/variables/catalogIdentifier";
74
74
var request = new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ;
75
75
request . Headers . Add ( "Authorization" , $ "Bearer { key } ") ;
76
- request . Headers . Add ( "User-Agent" , "HttpClientFactory-Sample " ) ;
76
+ request . Headers . Add ( "User-Agent" , "GitHubToCatalogYaml " ) ;
77
77
78
78
var response = await _httpClient . SendAsync ( request ) ;
79
79
if ( response . IsSuccessStatusCode )
@@ -90,16 +90,40 @@ public async Task<string> GetCatalogIdentifierAsync()
90
90
return null ;
91
91
}
92
92
93
+ /// <summary>
94
+ /// Deletes a GitHub repository variable named 'catalogIdentifier'.
95
+ /// </summary>
96
+ /// <returns>A task representing the asynchronous operation, containing a boolean indicating whether the operation was successful.</returns>
97
+ public async Task < bool > DeleteCatalogIdentifierAsync ( )
98
+ {
99
+ var requestUrl = $ "{ githubRoot } /actions/variables/catalogIdentifier";
100
+
101
+ var request = new HttpRequestMessage ( HttpMethod . Delete , requestUrl ) ;
102
+ request . Headers . Add ( "Authorization" , $ "Bearer { key } ") ;
103
+ request . Headers . Add ( "User-Agent" , "GitHubToCatalogYaml" ) ;
104
+
105
+ var response = await _httpClient . SendAsync ( request ) ;
106
+ if ( response . IsSuccessStatusCode )
107
+ {
108
+ _logger . LogInformation ( "Successfully deleted catalogIdentifier in GitHub repository." ) ;
109
+ return true ;
110
+ }
111
+
112
+ _logger . LogError ( $ "Failed to delete catalogIdentifier in GitHub repository: { response . StatusCode } ") ;
113
+ return false ;
114
+ }
115
+
116
+
93
117
/// <summary>
94
118
/// Retrieves the repository description from the GitHub repository.
95
119
/// </summary>
96
120
/// <returns>A task representing the asynchronous operation, containing the repository description as a string, or null if the retrieval fails.</returns>
97
121
public async Task < string > GetRepositoryDescriptionAsync ( )
98
122
{
99
- var requestUrl = $ "{ githubRoot } ";
123
+ var requestUrl = $ "{ githubRoot } "; // URL should already be in the format 'https://api.github.com/repos/{owner}/{repo}/'
100
124
var request = new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ;
101
125
request . Headers . Add ( "Authorization" , $ "Bearer { key } ") ;
102
- request . Headers . Add ( "User-Agent" , "HttpClientFactory-Sample " ) ;
126
+ request . Headers . Add ( "User-Agent" , "GitHubToCatalogYaml " ) ;
103
127
104
128
var response = await _httpClient . SendAsync ( request ) ;
105
129
if ( response . IsSuccessStatusCode )
@@ -110,23 +134,31 @@ public async Task<string> GetRepositoryDescriptionAsync()
110
134
{
111
135
return description . GetString ( ) ;
112
136
}
137
+ else
138
+ {
139
+ _logger . LogWarning ( "Repository description not found in the response." ) ;
140
+ }
141
+ }
142
+ else
143
+ {
144
+ _logger . LogError ( $ "Failed to retrieve repository description: { response . StatusCode } - { response . ReasonPhrase } ") ;
113
145
}
114
146
115
- _logger . LogError ( $ "Failed to retrieve repository description: { response . StatusCode } ") ;
116
147
return null ;
117
148
}
118
149
150
+
119
151
/// <summary>
120
152
/// Retrieves the topics (tags) from the GitHub repository's ABOUT section.
121
153
/// </summary>
122
154
/// <returns>A task representing the asynchronous operation, containing a list of repository topics (tags), or null if the retrieval fails.</returns>
123
155
public async Task < List < string > > GetRepositoryTopicsAsync ( )
124
156
{
125
- var requestUrl = $ "{ githubRoot } topics";
157
+ var requestUrl = $ "{ githubRoot } / topics";
126
158
var request = new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ;
127
159
request . Headers . Add ( "Authorization" , $ "Bearer { key } ") ;
128
160
request . Headers . Add ( "Accept" , "application/vnd.github.mercy-preview+json" ) ;
129
- request . Headers . Add ( "User-Agent" , "HttpClientFactory-Sample " ) ;
161
+ request . Headers . Add ( "User-Agent" , "GitHubToCatalogYaml " ) ;
130
162
131
163
var response = await _httpClient . SendAsync ( request ) ;
132
164
if ( response . IsSuccessStatusCode )
0 commit comments