Skip to content

Commit 323cdf8

Browse files
committed
Update trusted author handling
- Separate member and collaborator configurations - Separate trusted apps from the member and collaborator handling Signed-off-by: Dale Haiducek <[email protected]>
1 parent 4be743f commit 323cdf8

File tree

4 files changed

+148
-15
lines changed

4 files changed

+148
-15
lines changed

prow/plugins/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,15 @@ func (w Welcome) getRepos() []string {
694694

695695
// Dco is config for the DCO (https://developercertificate.org/) checker plugin.
696696
type Dco struct {
697-
// SkipDCOCheckForMembers is used to skip DCO check for trusted org members
697+
// SkipDCOCheckForMembers is used to skip DCO check for org members.
698698
SkipDCOCheckForMembers bool `json:"skip_dco_check_for_members,omitempty"`
699699
// TrustedApps defines list of apps which commits will not be checked for DCO singoff.
700700
// The list should contain usernames of each GitHub App without [bot] suffix.
701-
// By default, this option is ignored.
702701
TrustedApps []string `json:"trusted_apps,omitempty"`
703702
// TrustedOrg is the org whose members' commits will not be checked for DCO signoff
704-
// if the skip DCO option is enabled. The default is the PR's org.
703+
// if the SkipDCOCheckForMembers option is enabled. The default is the PR's org.
705704
TrustedOrg string `json:"trusted_org,omitempty"`
706-
// SkipDCOCheckForCollaborators is used to skip DCO check for trusted org members
705+
// SkipDCOCheckForCollaborators is used to skip DCO check for repository collaborators.
707706
SkipDCOCheckForCollaborators bool `json:"skip_dco_check_for_collaborators,omitempty"`
708707
// ContributingRepo is used to point users to a different repo containing CONTRIBUTING.md
709708
ContributingRepo string `json:"contributing_repo,omitempty"`

prow/plugins/dco/dco.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func helpProvider(config *plugins.Configuration, enabledRepos []config.OrgRepo)
7979
Dco: map[string]*plugins.Dco{
8080
"org/repo": {
8181
SkipDCOCheckForMembers: true,
82+
TrustedApps: []string{"trusted-app"},
8283
TrustedOrg: "org",
8384
SkipDCOCheckForCollaborators: true,
8485
ContributingRepo: "other-org/other-repo",
@@ -124,14 +125,37 @@ type commentPruner interface {
124125
}
125126

126127
// filterTrustedUsers checks whether the commits are from a trusted user and returns those that are not
127-
func filterTrustedUsers(gc gitHubClient, l *logrus.Entry, skipDCOCheckForCollaborators bool, trustedApps []string, trustedOrg, org, repo string, allCommits []github.RepositoryCommit) ([]github.RepositoryCommit, error) {
128+
func filterTrustedUsers(gc gitHubClient, l *logrus.Entry, config plugins.Dco, org, repo string, allCommits []github.RepositoryCommit) ([]github.RepositoryCommit, error) {
128129
untrustedCommits := make([]github.RepositoryCommit, 0, len(allCommits))
129130

131+
var trustedResponse trigger.TrustedUserResponse
132+
130133
for _, commit := range allCommits {
131-
trustedResponse, err := trigger.TrustedUser(gc, !skipDCOCheckForCollaborators, trustedApps, trustedOrg, commit.Author.Login, org, repo)
132-
if err != nil {
133-
return nil, fmt.Errorf("Error checking is member trusted: %w", err)
134+
trustedResponse.IsTrusted = false
135+
136+
// Handle TrustedApps separately (since Trigger checks this last and doesn't have member/collaborator configurable handling)
137+
for _, trustedApp := range config.TrustedApps {
138+
if tUser := strings.TrimSuffix(commit.Author.Login, "[bot]"); tUser == trustedApp {
139+
trustedResponse.IsTrusted = true
140+
break
141+
}
134142
}
143+
144+
if !trustedResponse.IsTrusted && (config.SkipDCOCheckForMembers || config.SkipDCOCheckForCollaborators) {
145+
trustedOrg := config.TrustedOrg
146+
147+
// If SkipDCOCheckforMembers is disabled, make sure the trusted org is empty
148+
if !config.SkipDCOCheckForMembers {
149+
trustedOrg = ""
150+
}
151+
152+
var err error
153+
trustedResponse, err = trigger.TrustedUser(gc, !config.SkipDCOCheckForCollaborators, config.TrustedApps, trustedOrg, commit.Author.Login, org, repo)
154+
if err != nil {
155+
return nil, fmt.Errorf("Error checking is member trusted: %w", err)
156+
}
157+
}
158+
135159
if !trustedResponse.IsTrusted {
136160
l.Debugf("Member %s is not trusted", commit.Author.Login)
137161
untrustedCommits = append(untrustedCommits, commit)
@@ -296,8 +320,8 @@ func handle(config plugins.Dco, gc gitHubClient, cp commentPruner, log *logrus.E
296320
return err
297321
}
298322

299-
if config.SkipDCOCheckForMembers || config.SkipDCOCheckForCollaborators {
300-
commitsMissingDCO, err = filterTrustedUsers(gc, l, config.SkipDCOCheckForCollaborators, config.TrustedApps, config.TrustedOrg, org, repo, commitsMissingDCO)
323+
if config.SkipDCOCheckForMembers || config.SkipDCOCheckForCollaborators || len(config.TrustedApps) > 0 {
324+
commitsMissingDCO, err = filterTrustedUsers(gc, l, config, org, repo, commitsMissingDCO)
301325
if err != nil {
302326
l.WithError(err).Infof("Error running trusted org member check against commits in PR")
303327
return err

prow/plugins/dco/dco_test.go

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,39 @@ Instructions for interacting with me using PR comments are available [here](http
255255

256256
addedLabel: fmt.Sprintf("/#3:%s", dcoYesLabel),
257257
expectedStatus: github.StatusSuccess,
258+
}, {
259+
name: "should fail if an user is member of the trusted org but skip member check is false (commit non-signed)",
260+
config: plugins.Dco{
261+
SkipDCOCheckForMembers: false,
262+
TrustedOrg: "kubernetes",
263+
},
264+
pullRequestEvent: github.PullRequestEvent{
265+
Action: github.PullRequestActionOpened,
266+
PullRequest: github.PullRequest{Number: 3, Head: github.PullRequestBranch{SHA: "sha"}},
267+
},
268+
commits: []github.RepositoryCommit{
269+
{
270+
SHA: "sha",
271+
Commit: github.GitCommit{Message: "not signed off"},
272+
Author: github.User{
273+
Login: "test",
274+
},
275+
},
276+
},
277+
issueState: "open",
278+
hasDCONo: true,
279+
hasDCOYes: false,
280+
281+
addedLabel: fmt.Sprintf("/#3:%s", dcoNoLabel),
282+
expectedStatus: github.StatusFailure,
283+
addedComment: "/#3:Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.\n\n" +
284+
":memo: **Please follow instructions in the [contributing guide](https://github.com///blob/master/CONTRIBUTING.md) to update your " +
285+
"commits with the DCO**\n\nFull details of the Developer Certificate of Origin can be found at " +
286+
"[developercertificate.org](https://developercertificate.org/).\n\n**The list of commits missing DCO signoff**:\n\n" +
287+
"- [sha](https://github.com///commits/sha) not signed off\n\n<details>\n\nInstructions for interacting with me using PR comments are " +
288+
"available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related " +
289+
"to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) " +
290+
"repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).\n</details>\n",
258291
},
259292
{
260293
name: "should add label and update status context if an user is member of the trusted org (one commit signed, one non-signed)",
@@ -415,6 +448,55 @@ Full details of the Developer Certificate of Origin can be found at [developerce
415448
416449
<details>
417450
451+
Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
452+
</details>
453+
`,
454+
},
455+
{
456+
name: "should fail dco check as one unsigned commit is not from the trusted app",
457+
config: plugins.Dco{
458+
SkipDCOCheckForMembers: false,
459+
TrustedOrg: "kubernetes",
460+
TrustedApps: []string{"my-trusted-app"},
461+
},
462+
pullRequestEvent: github.PullRequestEvent{
463+
Action: github.PullRequestActionOpened,
464+
PullRequest: github.PullRequest{Number: 3, Head: github.PullRequestBranch{SHA: "sha"}},
465+
},
466+
commits: []github.RepositoryCommit{
467+
{
468+
SHA: "sha",
469+
Commit: github.GitCommit{Message: "not signed off"},
470+
Author: github.User{
471+
Login: "test",
472+
},
473+
},
474+
{
475+
SHA: "sha2",
476+
Commit: github.GitCommit{Message: "not signed off"},
477+
Author: github.User{
478+
Login: "my-trusted-app",
479+
},
480+
},
481+
},
482+
issueState: "open",
483+
hasDCONo: false,
484+
hasDCOYes: false,
485+
486+
addedLabel: fmt.Sprintf("/#3:%s", dcoNoLabel),
487+
expectedStatus: github.StatusFailure,
488+
addedComment: `/#3:Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.
489+
490+
:memo: **Please follow instructions in the [contributing guide](https://github.com///blob/master/CONTRIBUTING.md) to update your commits with the DCO**
491+
492+
Full details of the Developer Certificate of Origin can be found at [developercertificate.org](https://developercertificate.org/).
493+
494+
**The list of commits missing DCO signoff**:
495+
496+
- [sha](https://github.com///commits/sha) not signed off
497+
498+
<details>
499+
418500
Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
419501
</details>
420502
`,
@@ -463,7 +545,7 @@ Instructions for interacting with me using PR comments are available [here](http
463545
{
464546
name: "should skip dco check as commit is from a collaborator",
465547
config: plugins.Dco{
466-
SkipDCOCheckForMembers: true,
548+
SkipDCOCheckForMembers: false,
467549
SkipDCOCheckForCollaborators: true,
468550
TrustedOrg: "kubernetes",
469551
},
@@ -771,6 +853,35 @@ Instructions for interacting with me using PR comments are available [here](http
771853
},
772854
issueState: "open",
773855

856+
expectedStatus: github.StatusSuccess,
857+
},
858+
{
859+
name: "should succeed from a trusted app",
860+
config: plugins.Dco{
861+
SkipDCOCheckForMembers: false,
862+
TrustedApps: []string{"my-trusted-app"},
863+
},
864+
commentEvent: github.GenericCommentEvent{
865+
IssueState: "open",
866+
Action: github.GenericCommentActionCreated,
867+
Body: "/check-dco",
868+
IsPR: true,
869+
Number: 3,
870+
},
871+
pullRequests: map[int]*github.PullRequest{
872+
3: {Number: 3, Head: github.PullRequestBranch{SHA: "sha"}},
873+
},
874+
commits: []github.RepositoryCommit{
875+
{
876+
SHA: "sha",
877+
Commit: github.GitCommit{Message: "not a sign off"},
878+
Author: github.User{
879+
Login: "my-trusted-app",
880+
},
881+
},
882+
},
883+
issueState: "open",
884+
774885
expectedStatus: github.StatusSuccess,
775886
},
776887
}

prow/plugins/plugin-config-documented.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,16 @@ dco:
369369
contributing_path: ' '
370370
# ContributingRepo is used to point users to a different repo containing CONTRIBUTING.md
371371
contributing_repo: ' '
372-
# SkipDCOCheckForCollaborators is used to skip DCO check for trusted org members
372+
# SkipDCOCheckForCollaborators is used to skip DCO check for repository collaborators.
373373
skip_dco_check_for_collaborators: true
374-
# SkipDCOCheckForMembers is used to skip DCO check for trusted org members
374+
# SkipDCOCheckForMembers is used to skip DCO check for org members.
375375
skip_dco_check_for_members: true
376376
# TrustedApps defines list of apps which commits will not be checked for DCO singoff.
377377
# The list should contain usernames of each GitHub App without [bot] suffix.
378-
# By default, this option is ignored.
379378
trusted_apps:
380379
- ""
381380
# TrustedOrg is the org whose members' commits will not be checked for DCO signoff
382-
# if the skip DCO option is enabled. The default is the PR's org.
381+
# if the SkipDCOCheckForMembers option is enabled. The default is the PR's org.
383382
trusted_org: ' '
384383
# ExternalPlugins is a map of repositories (eg "k/k") to lists of
385384
# external plugins.

0 commit comments

Comments
 (0)