From afc35b6fcbcdabf84d2c1e21209aace0da8f05b7 Mon Sep 17 00:00:00 2001 From: davidwin93 Date: Fri, 13 Oct 2023 10:49:36 -0600 Subject: [PATCH] add merge PR support to Github --- pkg/vcs/github/client.go | 9 +++++++++ pkg/vcs/github/run_events_worker.go | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/vcs/github/client.go b/pkg/vcs/github/client.go index 85d624c..41bdbed 100644 --- a/pkg/vcs/github/client.go +++ b/pkg/vcs/github/client.go @@ -64,6 +64,15 @@ func (c *Client) GetMergeRequestApprovals(ctx context.Context, id int, project s } return pr, nil } +func (c *Client) MergeMR(ctx context.Context, mrIID int, project string) error { + projectParts, err := splitFullName(project) + if err != nil { + utils.CreatePermanentError(err) + } + _, _, err = c.client.PullRequests.Merge(c.ctx, projectParts[0], projectParts[1], mrIID, "", nil) + + return err +} // Go over all comments on a PR, trying to grab any old TFC run urls and deleting the bodies func (c *Client) GetOldRunUrls(ctx context.Context, prID int, fullName string, rootCommentID int) (string, error) { diff --git a/pkg/vcs/github/run_events_worker.go b/pkg/vcs/github/run_events_worker.go index d54ffc9..73d077c 100644 --- a/pkg/vcs/github/run_events_worker.go +++ b/pkg/vcs/github/run_events_worker.go @@ -81,5 +81,11 @@ func (w *RunEventsWorker) postRunStatusComment(ctx context.Context, run *tfe.Run ) } - + if run.Status == tfe.RunApplied { + if len(run.TargetAddrs) > 0 { + return + } + // The applying phase of a run has completed. + w.client.MergeMR(ctx, rmd.GetMRInternalID(), rmd.GetMRProjectNameWithNamespace()) + } }