Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge on successful apply #39

Merged
merged 16 commits into from
Oct 24, 2023
Merged

Merge on successful apply #39

merged 16 commits into from
Oct 24, 2023

Conversation

davidwin93
Copy link
Collaborator

@davidwin93 davidwin93 commented Oct 13, 2023

Resolves issue #19

Remaining work:

  • add config option at global and project level to allow disabling this feature [x]
  • update comments posted to Github/Gitlab that indicate if auto merge is enabled [x]

This will only merge after a full apply. This allows multiple targeted applies to be used without concern that the MR will be auto merged.

Screen Cast 2023-10-16 at 10 28 57 AM

Screen Shot 2023-10-16 at 11 23 53 AM

Tested the following situations:

  • autoMerge disabled and enabled in .tfbuddy config
  • TFBUDDY_ALLOW_AUTO_MERGE in deployment set to false and not present
  • targeted plans and applies to ensure that a MR is only merged after a full apply

@davidwin93 davidwin93 force-pushed the Merge-On-Apply branch 3 times, most recently from 0d98b79 to 0779625 Compare October 13, 2023 17:22
@davidwin93 davidwin93 marked this pull request as draft October 14, 2023 03:39
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
@davidwin93 davidwin93 marked this pull request as ready for review October 17, 2023 16:07
@@ -639,6 +639,8 @@ func (t *TFCTrigger) publishRunToStream(ctx context.Context, run *tfe.Run) error
DiscussionID: t.GetMergeRequestDiscussionID(),
RootNoteID: t.GetMergeRequestRootNoteID(),
VcsProvider: t.GetVcsProvider(),
//set Auto Merge if both conditions are met.
AutoMerge: cfgWS.AutoMerge && cfgWS.Mode == "apply-before-merge",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to surface some kind of error message if auto merge is configured for "merge-before-apply" or "tfc-vcs-repo"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, similar question for "automerge=true" but global auto merge is disabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now log if either condition occurs. Plus the help text in the MR will indicate that a manual merge is required.

)

func getProperApplyText(rmd runstream.RunMetadata, wsName string) string {
if rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than check both rmd.GetAutoMerge() && vcs.IsGlobalAutoMergeEnabled() in 5 different places, any reason to either put the global check into GetAutoMerge or check it once before creating the runstream.TFRunMetadata in tfc_trigger.go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of putting it in GetAutoMerge. That way if there's a long queued run and the global setting changes it would be respected.

@davidwin93 davidwin93 force-pushed the Merge-On-Apply branch 2 times, most recently from bdca8a3 to 58bf1cb Compare October 18, 2023 02:07
docs/usage.md Outdated
@@ -50,6 +50,8 @@ env:
TFBUDDY_PROJECT_ALLOW_LIST: tfc-project/
TFBUDDY_WORKSPACE_ALLOW_LIST: tfc-workspace
TFBUDDY_DEFAULT_TFC_ORGANIZATION: companyX
# Optional setting to disable auto merging MRs after a successful apply. This is enabled by default.
TFBUDDY_ENABLE_AUTO_MERGE: "false"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, one last thing. since this doesn't enable it, but rather prevents it from being enabled per repo, can we rename this "ALLOW_AUTO_MERGE", or something similar?

Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
@davidwin93
Copy link
Collaborator Author

If an apply returns no changes we will still auto merge

Gitlab:
Screen Cast 2023-10-19 at 10 18 02 AM

Github:
Screen Cast 2023-10-19 at 10 22 14 AM

Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
…for nats dedupe timeout

Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
Copy link
Collaborator

@djeebus djeebus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! only thing i can see in your most recent commits is the rmd.GetAction() == "apply" is kind of scary, it'd be nice to have an enum or something there, but go kind of suck w/ enums. maybe just a constant to avoid the strings? not important though, still approved!

Signed-off-by: davidwin93 <dave.winiarski@zapier.com>
@davidwin93 davidwin93 merged commit 5c713dc into main Oct 24, 2023
4 checks passed
@davidwin93 davidwin93 deleted the Merge-On-Apply branch October 24, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants