Skip to content

Commit

Permalink
Put deleting behind env var, cleanup func sig
Browse files Browse the repository at this point in the history
  • Loading branch information
polyrain committed Jul 19, 2023
1 parent 85753c4 commit 0f1c033
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/mocks/mock_vcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/vcs/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Client) GetMergeRequestApprovals(id int, project string) (vcs.MRApprove
}

// Go over all comments on a PR, trying to grab any old TFC run urls and deleting the bodies
func (c *Client) GetOldRunUrls(prID int, fullName string, rootCommentID int, deleteComment bool) (string, error) {
func (c *Client) GetOldRunUrls(prID int, fullName string, rootCommentID int) (string, error) {
log.Debug().Msg("pruneComments")
projectParts, err := splitFullName(fullName)
if err != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *Client) GetOldRunUrls(prID int, fullName string, rootCommentID int, del
oldRunBlock = oldRunBlockTest
}

if deleteComment && comment.GetID() != int64(rootCommentID) {
if os.Getenv("TFBUDDY_DELETE_OLD_COMMENTS") != "" && comment.GetID() != int64(rootCommentID) {
log.Debug().Msgf("Deleting comment %d", comment.GetID())
_, err := c.client.Issues.DeleteComment(c.ctx, projectParts[0], projectParts[1], comment.GetID())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vcs/gitlab/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *GitlabClient) GetCommitStatuses(projectID, commitSHA string) []*gogitla
}

// Crawl the comments on this MR for tfbuddy comments, grab any TFC urls out of them, and delete them.
func (c *GitlabClient) GetOldRunUrls(mrIID int, project string, rootNoteID int, deleteNotes bool) (string, error) {
func (c *GitlabClient) GetOldRunUrls(mrIID int, project string, rootNoteID int) (string, error) {
log.Debug().Str("projectID", project).Int("mrIID", mrIID).Msg("pruning notes")
notes, _, err := c.client.Notes.ListMergeRequestNotes(project, mrIID, &gogitlab.ListMergeRequestNotesOptions{})
if err != nil {
Expand Down Expand Up @@ -139,7 +139,7 @@ func (c *GitlabClient) GetOldRunUrls(mrIID int, project string, rootNoteID int,
if oldRunBlockTest != "" {
oldRunBlock = oldRunBlockTest
}
if deleteNotes && note.ID != rootNoteID {
if os.Getenv("TFBUDDY_DELETE_OLD_COMMENTS") != "" && note.ID != rootNoteID {
log.Debug().Str("projectID", project).Int("mrIID", mrIID).Msgf("deleting note %d", note.ID)
_, err := c.client.Notes.DeleteMergeRequestNote(project, mrIID, note.ID)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vcs/gitlab/mr_comment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func (p *RunStatusUpdater) postRunStatusComment(run *tfe.Run, rmd runstream.RunM

var oldUrls string
var err error
// TODO: Make this configurable behaviour

if run.Status == tfe.RunErrored || run.Status == tfe.RunCanceled || run.Status == tfe.RunDiscarded || run.Status == tfe.RunPlannedAndFinished {
oldUrls, err = p.client.GetOldRunUrls(rmd.GetMRInternalID(), rmd.GetMRProjectNameWithNamespace(), int(rmd.GetRootNoteID()), true)
oldUrls, err = p.client.GetOldRunUrls(rmd.GetMRInternalID(), rmd.GetMRProjectNameWithNamespace(), int(rmd.GetRootNoteID()))
if err != nil {
log.Error().Err(err).Msg("could not retrieve old run urls")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type GitClient interface {
AddMergeRequestDiscussionReply(mrIID int, project, discussionID, comment string) (MRNote, error)
SetCommitStatus(projectWithNS string, commitSHA string, status CommitStatusOptions) (CommitStatus, error)
GetPipelinesForCommit(projectWithNS string, commitSHA string) ([]ProjectPipeline, error)
GetOldRunUrls(mrIID int, project string, rootCommentID int, deleteNotes bool) (string, error)
GetOldRunUrls(mrIID int, project string, rootCommentID int) (string, error)
}
type GitRepo interface {
FetchUpstreamBranch(string) error
Expand Down

0 comments on commit 0f1c033

Please sign in to comment.