-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: PR check status to show summary e.g. Plan: 1 to add, 0 to change, 1 to destroy
#2699
Conversation
741a94e
to
ea7be17
Compare
@@ -51,14 +51,13 @@ func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull model | |||
var descripWords string | |||
switch status { | |||
case models.PendingCommitStatus: | |||
descripWords = "in progress..." | |||
descripWords = genProjectStatusDescription(cmdName.String(), "in progress...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @albertorm95 !
Could you also add test(s) for this to verify the descripWords
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can create one, just that I don't understand my current test fail :(
--- FAIL: TestProjectOutputWrapper
is this using the checks api?
…On Sun, Nov 20, 2022, 3:13 p.m. Alberto Rojas ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In server/events/commit_status_updater.go
<#2699 (comment)>
:
> @@ -51,14 +51,13 @@ func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull model
var descripWords string
switch status {
case models.PendingCommitStatus:
- descripWords = "in progress..."
+ descripWords = genProjectStatusDescription(cmdName.String(), "in progress...")
Sure, I can create one, just that I don't understand my current test fail
:(
--- FAIL: TestProjectOutputWrapper
—
Reply to this email directly, view it on GitHub
<#2699 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQ3ERFF6VUT7NLEP4OLI23WJKWBFANCNFSM6AAAAAASGBUB44>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
sorry @jamengual, what do you mean with that? |
I might be confused, @nitrocode was this the same. issue you opened, or there was another one to implement the checks api (like spacelift checks) |
@@ -167,6 +167,7 @@ func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, c | |||
|
|||
// ensures we are differentiating between project level command and overall command | |||
result := execute(ctx) | |||
ctx.CommandResult = result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ ctx.CommandResult = result
This change is making the TestProjectOutputWrapper
to fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albertorm95 is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albertorm95 it's odd that this line is causing the failure because it should not affect the result
if statement on line 172. I imagine the code isn't falling into that if block because that is where SetJobURLWithStatus
is called.
Perhaps it's a test issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it looks like a test issue
mockJobURLSetter.VerifyWasCalled(Once()).SetJobURLWithStatus(ctx, c.CommandName, models.PendingCommitStatus) |
atlantis/server/events/models/commit_status.go
Lines 22 to 38 in 9ca57d6
const ( | |
PendingCommitStatus CommitStatus = iota | |
SuccessCommitStatus | |
FailedCommitStatus | |
) | |
func (s CommitStatus) String() string { | |
switch s { | |
case PendingCommitStatus: | |
return "pending" | |
case SuccessCommitStatus: | |
return "success" | |
case FailedCommitStatus: | |
return "failed" | |
} | |
return "failed" | |
} |
Basically, since you changed the status of the pr check, the test still thinks the status should be pending/success/failed.
Please update the test and it should work as expected.
cc: @albertorm95
@jamengual yes that was a separate issue. The ChecksAPI is specific for the github app and would move the PR comments to the Github native ChecksAPI page. This change will affect both Github App and non Github App since it will impact the status checks. Hopefully the future ChecksAPI implementation in the other issue will take advantage of the updated status messages from this PR. :) |
I am not sure how to comply with the |
I'm unsure on how to fix that failure. The error is saying that After that one is fixed, you will have to update |
@@ -20,6 +20,8 @@ const ( | |||
// be executed for a project. | |||
type ProjectContext struct { | |||
CommandName Name | |||
// CommandResult represent the Terraform outputs after the command execution. | |||
CommandResult ProjectResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProjectContext
is used for command execution context. So you should not use ProjectContext
as a mutable variable like ctx.CommandResult = result
.
In this case, it is better to add result ProjectResult
arg into SetJobURLWithStatus
like SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, projectResult ProjectResult) error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently TestProjectOutputWrapper
is failed by following reasons.
- test mock following calls which use same
ctx
.
mockJobURLSetter.VerifyWasCalled(Once()).SetJobURLWithStatus(ctx, c.CommandName, models.PendingCommitStatus)
mockJobURLSetter.VerifyWasCalled(Once()).SetJobURLWithStatus(ctx, c.CommandName, expCommitStatus)
- actual invocations are used different ctx which has different
CommandResult
.
Actual interactions with this mock were:
SetJobURLWithStatus(command.ProjectContext{CommandName:0, CommandResult:command.ProjectResult{Command:0, RepoRelDir:"", Workspace:"", Error:error(nil), Failure:"", PlanSuccess:(*models.PlanSuccess)(nil), PolicyCheckSuccess:(*models.PolicyCheckSuccess)(nil), ApplySuccess:"", VersionSuccess:"", ProjectName:""}, ApplyCmd:"", ApplyRequirements:[]string(nil), AutomergeEnabled:false, ParallelApplyEnabled:false, ParallelPlanEnabled:false, ParallelPolicyCheckEnabled:false, AutoplanEnabled:false, BaseRepo:models.Repo{FullName:"", Owner:"", Name:"", CloneURL:"", SanitizedCloneURL:"", VCSHost:models.VCSHost{Hostname:"", Type:0}}, EscapedCommentArgs:[]string(nil), HeadRepo:models.Repo{FullName:"", Owner:"", Name:"", CloneURL:"", SanitizedCloneURL:"", VCSHost:models.VCSHost{Hostname:"", Type:0}}, Log:(*logging.StructuredLogger)(0xc000636b00), Scope:tally.Scope(nil), PullReqStatus:models.PullReqStatus{ApprovalStatus:models.ApprovalStatus{IsApproved:false, ApprovedBy:"", Date:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)}, Mergeable:false}, ProjectPlanStatus:0, Pull:models.PullRequest{Num:0, HeadCommit:"", URL:"", HeadBranch:"", BaseBranch:"", Author:"", State:0, BaseRepo:models.Repo{FullName:"", Owner:"", Name:"", CloneURL:"", SanitizedCloneURL:"", VCSHost:models.VCSHost{Hostname:"", Type:0}}}, ProjectName:"", RepoConfigVersion:0, RePlanCmd:"", RepoRelDir:".", Steps:[]valid.Step{valid.Step{StepName:"plan", ExtraArgs:[]string(nil), RunCommand:"", EnvVarName:"", EnvVarValue:""}}, TerraformVersion:(*version.Version)(nil), User:models.User{Username:""}, Verbose:false, Workspace:"default", PolicySets:valid.PolicySets{Version:(*version.Version)(nil), Owners:valid.PolicyOwners{Users:[]string(nil)}, PolicySets:[]valid.PolicySet(nil)}, DeleteSourceBranchOnMerge:false, RepoLocking:false, JobID:"", ExecutionOrderGroup:0}, 1, 0)
SetJobURLWithStatus(command.ProjectContext{CommandName:0, CommandResult:command.ProjectResult{Command:0, RepoRelDir:"", Workspace:"", Error:error(nil), Failure:"", PlanSuccess:(*models.PlanSuccess)(0xc0000ae960), PolicyCheckSuccess:(*models.PolicyCheckSuccess)(nil), ApplySuccess:"exists", VersionSuccess:"", ProjectName:""}, ApplyCmd:"", ApplyRequirements:[]string(nil), AutomergeEnabled:false, ParallelApplyEnabled:false, ParallelPlanEnabled:false, ParallelPolicyCheckEnabled:false, AutoplanEnabled:false, BaseRepo:models.Repo{FullName:"", Owner:"", Name:"", CloneURL:"", SanitizedCloneURL:"", VCSHost:models.VCSHost{Hostname:"", Type:0}}, EscapedCommentArgs:[]string(nil), HeadRepo:models.Repo{FullName:"", Owner:"", Name:"", CloneURL:"", SanitizedCloneURL:"", VCSHost:models.VCSHost{Hostname:"", Type:0}}, Log:(*logging.StructuredLogger)(0xc000636b00), Scope:tally.Scope(nil), PullReqStatus:models.PullReqStatus{ApprovalStatus:models.ApprovalStatus{IsApproved:false, ApprovedBy:"", Date:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)}, Mergeable:false}, ProjectPlanStatus:0, Pull:models.PullRequest{Num:0, HeadCommit:"", URL:"", HeadBranch:"", BaseBranch:"", Author:"", State:0, BaseRepo:models.Repo{FullName:"", Owner:"", Name:"", CloneURL:"", SanitizedCloneURL:"", VCSHost:models.VCSHost{Hostname:"", Type:0}}}, ProjectName:"", RepoConfigVersion:0, RePlanCmd:"", RepoRelDir:".", Steps:[]valid.Step{valid.Step{StepName:"plan", ExtraArgs:[]string(nil), RunCommand:"", EnvVarName:"", EnvVarValue:""}}, TerraformVersion:(*version.Version)(nil), User:models.User{Username:""}, Verbose:false, Workspace:"default", PolicySets:valid.PolicySets{Version:(*version.Version)(nil), Owners:valid.PolicyOwners{Users:[]string(nil)}, PolicySets:[]valid.PolicySet(nil)}, DeleteSourceBranchOnMerge:false, RepoLocking:false, JobID:"", ExecutionOrderGroup:0}, 1, 1)
Mutable variables are difficult to maintain it. I recommend you to change like above comment. @albertorm95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! @albertorm95 could you find a way to make these tests work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with that solution, but it gets very complex.
Update SetJobURLWithStatus
means to also update UpdateProject
which is in a lot of places and makes me to update a lot of test cases, I have no experience with those mocks 😢
cc: @krrrr38 @nitrocode
a0f29b2
to
d6d8977
Compare
Plan Succeeded
show Plan: 1 to add, 0 to change, 1 to destroy
Plan: 1 to add, 0 to change, 1 to destroy
👋🏽 this looks like a really nice to have feature, what's the status of this? I'm asking because after the work done (pending merge) in #2907 I've been exploring some options to have better information passed on to the templates, in order to be able to override them with more useful stats, and I've a local branch that adds a stats structure to |
Unfortunately, i believe it's stalled. We're always looking for contributors. Please feel free if you can help guide the pr author or please feel free to take over the PR or create a new one to get this over the line |
@nitrocode thanks for the quick response. I'll see what I can do, as this one seem to be focused on using the checks APIs, whereas my local branch is mostly focused on the rendered templates for commenting. |
…-status feat: PR check status to show summary e.g. `Plan: 1 to add, 0 to change, 1 to destroy`
what
Plan contains no changes.
Plan: 1 to add, 0 to change, 0 to destroy
why
references
Plan Succeeded
showPlan: 1 to add, 0 to change, 1 to destroy
#2625