Skip to content

Commit

Permalink
Make sure we test for Pending Approval
Browse files Browse the repository at this point in the history
When the user is not allowed make sure we check the test are in Pending
Approval

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel authored and savitaashture committed Jul 7, 2023
1 parent f7cb9ed commit 1eb8efe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/content/docs/guide/policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
title: Policy on actions
weight: 9
---
# Policy on Pipeline as Code actions
# Policy on Pipelines-as-Code actions

Pipelines as Code has the concepts of Policy to let you control an action allowed
Pipelines-as-Code has the concepts of Policy to let you control an action allowed
to be executed by a set of users belonging to a Team on an Organisation as
defined on GitHub or other Git Providers (only GitHub and Gitea is supported at
the moment).

## List of actions supported

* `pull_request` - This action is triggering the CI on Pipelines as Code,
* `pull_request` - This action is triggering the CI on Pipelines-as-Code,
specifying a team will only allow the members of the team to trigger the CI
and will not allow other members regadless if they are Owners or Collaborators
of the repository or the Organization. The OWNERS file is still taken into
account and will as well allow the members of the OWNERS file to trigger the
CI.
* `ok_to_test` - This action will let a user belonging to the allowed team to
issue a `/ok-to-test` comment on a Pull Request to trigger the CI on
Pipelines as Code, this let running the CI on Pull Request contributed by a
Pipelines-as-Code, this let running the CI on Pull Request contributed by a
non collaborator of the repository or the organisation. This apply to the
`/test` and `/retest` commands as well. This take precendence on the
`pull_request` action.
Expand Down
4 changes: 2 additions & 2 deletions test/gitea_access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestGiteaACLOrgPendingApproval(t *testing.T) {
assert.NilError(t, err)

topts.PullRequest = tgitea.CreateForkPullRequest(t, topts, secondcnx, "", "echo Hello from user "+topts.TargetRefName)
topts.CheckForStatus = "pending"
topts.CheckForStatus = "Skipped"
tgitea.WaitForStatus(t, topts, topts.PullRequest.Head.Sha, "", false)
topts.Regexp = regexp.MustCompile(`.*is skipping this commit.*`)
tgitea.WaitForPullRequestCommentMatch(t, topts)
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestGiteaACLCommentsAllowing(t *testing.T) {
assert.NilError(t, err)

topts.PullRequest = tgitea.CreateForkPullRequest(t, topts, secondcnx, "", "echo Hello from user "+topts.TargetRefName)
topts.CheckForStatus = "pending"
topts.CheckForStatus = "Skipped"
tgitea.WaitForStatus(t, topts, topts.PullRequest.Head.Sha, "", false)
topts.Regexp = regexp.MustCompile(`.*is skipping this commit.*`)
tgitea.WaitForPullRequestCommentMatch(t, topts)
Expand Down
1 change: 1 addition & 0 deletions test/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ func TestGiteaParamsOnRepoCRWithCustomConsole(t *testing.T) {
Value: "myconsole",
},
},
StatusOnlyLatest: true,
}
topts.TargetRefName = names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")
topts.TargetNS = topts.TargetRefName
Expand Down
23 changes: 20 additions & 3 deletions test/pkg/gitea/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

type TestOpts struct {
StatusOnlyLatest bool
OnOrg bool
NoPullRequestCreation bool
SkipEventsCheck bool
Expand Down Expand Up @@ -139,7 +140,7 @@ func TestPR(t *testing.T, topts *TestOpts) func() {
topts.ParamsRun.Clients.Log.Infof("PullRequest %s has been created", pr.HTMLURL)

if topts.CheckForStatus != "" {
WaitForStatus(t, topts, topts.TargetRefName, "", false)
WaitForStatus(t, topts, topts.TargetRefName, "", topts.StatusOnlyLatest)
}

if topts.Regexp != nil {
Expand Down Expand Up @@ -195,16 +196,32 @@ func WaitForStatus(t *testing.T, topts *TestOpts, ref, forcontext string, onlyla
return statuses[i].ID < statuses[j].ID
})
if onlylatest {
statuses = statuses[len(statuses)-1:]
if len(statuses) > 1 {
statuses = statuses[len(statuses)-1:]
} else {
time.Sleep(5 * time.Second)
continue
}
}
for _, cstatus := range statuses {
if topts.CheckForStatus == "Skipped" {
if strings.HasSuffix(cstatus.Description, "Pending approval") {
numstatus++
break
}
}
if cstatus.State == "pending" {
continue
}
if forcontext != "" && cstatus.Context != forcontext {
continue
}
assert.Equal(t, string(cstatus.State), topts.CheckForStatus)
statuscheck := topts.CheckForStatus
if statuscheck != "" && statuscheck != string(cstatus.State) {
if statuscheck != cstatus.Description {
t.Errorf("Status on SHA: %s is %s from %s", ref, cstatus.State, cstatus.Context)
}
}
topts.ParamsRun.Clients.Log.Infof("Status on SHA: %s is %s from %s", ref, cstatus.State, cstatus.Context)
numstatus++
}
Expand Down

0 comments on commit 1eb8efe

Please sign in to comment.