@@ -135,6 +135,27 @@ func (c *Client) CreatePullRequest(ctx context.Context, repo *Repository, remote
135
135
return pullRequestMetadata , nil
136
136
}
137
137
138
+ // GetLabels fetches the labels for an issue.
139
+ func (c * Client ) GetLabels (ctx context.Context , number int ) ([]string , error ) {
140
+ slog .Info ("Getting labels" , "number" , number )
141
+ labels , _ , err := c .Issues .ListLabelsByIssue (ctx , c .repo .Owner , c .repo .Name , number , nil )
142
+ if err != nil {
143
+ return nil , err
144
+ }
145
+ var labelNames []string
146
+ for _ , label := range labels {
147
+ labelNames = append (labelNames , * label .Name )
148
+ }
149
+ return labelNames , nil
150
+ }
151
+
152
+ // ReplaceLabels replaces all labels for an issue.
153
+ func (c * Client ) ReplaceLabels (ctx context.Context , number int , labels []string ) error {
154
+ slog .Info ("Replacing labels" , "number" , number , "labels" , labels )
155
+ _ , _ , err := c .Issues .ReplaceLabelsForIssue (ctx , c .repo .Owner , c .repo .Name , number , labels )
156
+ return err
157
+ }
158
+
138
159
// AddLabelsToIssue adds labels to an existing issue in a GitHub repository.
139
160
func (c * Client ) AddLabelsToIssue (ctx context.Context , repo * Repository , number int , labels []string ) error {
140
161
slog .Info ("Labels added to issue" , "number" , number , "labels" , labels )
@@ -165,3 +186,56 @@ func FetchGitHubRepoFromRemote(repo gitrepo.Repository) (*Repository, error) {
165
186
166
187
return nil , fmt .Errorf ("could not find an 'origin' remote pointing to a GitHub https URL" )
167
188
}
189
+
190
+ // SearchPullRequests searches for pull requests in the repository using the provided raw query.
191
+ func (c * Client ) SearchPullRequests (ctx context.Context , query string ) ([]* PullRequest , error ) {
192
+ var prs []* PullRequest
193
+ opts := & github.SearchOptions {
194
+ ListOptions : github.ListOptions {PerPage : 100 },
195
+ }
196
+ for {
197
+ result , resp , err := c .Search .Issues (ctx , query , opts )
198
+ if err != nil {
199
+ return nil , err
200
+ }
201
+ for _ , issue := range result .Issues {
202
+ if issue .IsPullRequest () {
203
+ pr , _ , err := c .PullRequests .Get (ctx , c .repo .Owner , c .repo .Name , issue .GetNumber ())
204
+ if err != nil {
205
+ return nil , err
206
+ }
207
+ prs = append (prs , pr )
208
+ }
209
+ }
210
+ if resp .NextPage == 0 {
211
+ break
212
+ }
213
+ opts .Page = resp .NextPage
214
+ }
215
+ return prs , nil
216
+ }
217
+
218
+ // GetPullRequest gets a pull request by its number.
219
+ func (c * Client ) GetPullRequest (ctx context.Context , number int ) (* PullRequest , error ) {
220
+ pr , _ , err := c .PullRequests .Get (ctx , c .repo .Owner , c .repo .Name , number )
221
+ return pr , err
222
+ }
223
+
224
+ // CreateRelease creates a tag and release in the repository at the given commitish.
225
+ func (c * Client ) CreateRelease (ctx context.Context , tagName , name , body , commitish string ) (* github.RepositoryRelease , error ) {
226
+ r , _ , err := c .Repositories .CreateRelease (ctx , c .repo .Owner , c .repo .Name , & github.RepositoryRelease {
227
+ TagName : & tagName ,
228
+ Name : & name ,
229
+ Body : & body ,
230
+ TargetCommitish : & commitish ,
231
+ })
232
+ return r , err
233
+ }
234
+
235
+ // CreateIssueComment adds a comment to the issue number provided.
236
+ func (c * Client ) CreateIssueComment (ctx context.Context , number int , comment string ) error {
237
+ _ , _ , err := c .Issues .CreateComment (ctx , c .repo .Owner , c .repo .Name , number , & github.IssueComment {
238
+ Body : & comment ,
239
+ })
240
+ return err
241
+ }
0 commit comments