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

Added UnlockedApplyRequirement to support 🔒 and 🔓 emoji for atlantis apply #90

Merged
merged 13 commits into from
Aug 5, 2021

Conversation

Aayyush
Copy link

@Aayyush Aayyush commented Aug 2, 2021

No description provided.

@Aayyush Aayyush added enhancement New feature or request go Pull requests that update Go code labels Aug 2, 2021
Comment on lines 111 to 112
if r != ApprovedApplyRequirement && r != MergeableApplyRequirement && r != UnDivergedApplyRequirement && r != UnLockedApplyRequirement {
return fmt.Errorf("%q is not a valid apply_requirement, only %q, %q, %q and %q are supported", r, ApprovedApplyRequirement, MergeableApplyRequirement, UnDivergedApplyRequirement, UnLockedApplyRequirement)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this can be optimized instead of growing a large if statement haha

Copy link
Author

Choose a reason for hiding this comment

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

Yeah that sounds like a better approach 😅!

@@ -423,7 +423,7 @@ func (p ProjectCommandContext) ProjectCloneDir() string {
// SetScope sets the scope of the stats object field. Note: we deliberately set this on the value
// instead of a pointer since we want scopes to mirror our function stack
func (p ProjectCommandContext) SetScope(scope string) {
p.Scope = p.Scope.Scope(scope)
p.Scope = p.Scope.Scope(scope) //nolint
Copy link
Contributor

Choose a reason for hiding this comment

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

Why'd you add this tag?

Copy link
Author

Choose a reason for hiding this comment

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

I'm getting this warning without the tag ineffective assignment to field ProjectCommandContext.Scope (SA4005)go-staticcheck. I looked up the error code SA4005 and this is what I found SA4005 – Field assignment that will never be observed. Did you mean to use a pointer receiver. I'm not sure what it means.

Copy link
Author

Choose a reason for hiding this comment

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

Looks like it's passing all the tests without the //nolint tag as well. So, I have removed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh i think you found a bug of mine 😅 . I can address in another PR though.

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing!

cmd/server.go Outdated
@@ -87,6 +87,7 @@ const (
RepoWhitelistFlag = "repo-whitelist"
RepoAllowlistFlag = "repo-allowlist"
RequireApprovalFlag = "require-approval"
RequireUnlockedFlag = "require-unlocked"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe let's be specific so it's not confusing for future readers and let's call it: RequireSQUnlockedFlag

Copy link
Author

Choose a reason for hiding this comment

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

Done!

nishkrishnan
nishkrishnan previously approved these changes Aug 4, 2021
isValid := false
for _, applyRequirement := range applyRequirements {
if req == applyRequirement {
isValid = true
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just use a map instead of a list, this would become one line of code then?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm that's true! I'll change it to a map.

Copy link
Author

Choose a reason for hiding this comment

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

Looks like using a map makes the buildValidApplyRequirementsString() unpredictable causing the tests to fail occasionally. Should I just revert back to using a slice or should I change how we're generating the test statement?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably just account for that failure by sorting the result.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 134 to 144
var returnString strings.Builder
counter := 0
for _, applyReq := range applyRequirementsList {
if counter == len(applyRequirements)-1 {
returnString.WriteString(fmt.Sprintf("and %q", applyReq))
break
}
returnString.WriteString(fmt.Sprintf("%q, ", applyReq))
counter++
}
return returnString.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

lets just replace this logic in favor of: strings.Join(applyRequirementsList, ",") Also we can make the result of this function a global var since this never changes after startup.

The errorf statement above can then be "%q is not a valid apply_requirement, supported apply requirements are: ..."

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@Aayyush Aayyush merged commit 7629f25 into release-v0.17.1-lyft.1 Aug 5, 2021
@Aayyush Aayyush deleted the aayush/add-locks-feature branch August 5, 2021 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants