Skip to content

Commit

Permalink
add support for issue closing
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes committed Sep 12, 2024
1 parent d0c1661 commit 06751dd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libs/ci/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,28 @@ func (svc GithubService) GetCombinedPullRequestStatus(prNumber int) (string, err
}

func (svc GithubService) MergePullRequest(prNumber int) error {
isPullRequest, err := svc.IsPullRequest(prNumber)
if err != nil {
log.Printf("error checking if PR is issue: %v", err)
return fmt.Errorf("error checking if PR is issue: %v", err)
}

// if it is an issue, close it
if !isPullRequest {
closedState := "closed"
issueRequest := &github.IssueRequest{
State: &closedState,
}

_, _, err := svc.Client.Issues.Edit(context.Background(), svc.Owner, svc.RepoName, prNumber, issueRequest)
if err != nil {
log.Printf("error closing issue (merging): %v", err)
return fmt.Errorf("error closing issue (merging): %v", err)
}
return nil

}

pr, _, err := svc.Client.PullRequests.Get(context.Background(), svc.Owner, svc.RepoName, prNumber)
if err != nil {
log.Printf("error getting pull request: %v", err)
Expand Down

0 comments on commit 06751dd

Please sign in to comment.