-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,843 additions
and
9,960 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
packages/auto-approve/src/process-checks/node/owlbot-template-changes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {PullRequest} from '../../interfaces'; | ||
import { | ||
checkAuthor, | ||
checkTitleOrBody, | ||
reportIndividualChecks, | ||
} from '../../utils-for-pr-checking'; | ||
import {Octokit} from '@octokit/rest'; | ||
import {OwlBotTemplateChanges} from '../owl-bot-template-changes'; | ||
|
||
/** | ||
* The OwlBotTemplateChanges class's checkPR function returns | ||
* true if the PR: | ||
- has an author that is 'gcf-owl-bot[bot]' | ||
- has a title that does NOT include BREAKING, or ! | ||
- has a PR body that does not contain 'PiperOrigin-RevId' | ||
*/ | ||
export class OwlBotTemplateChangesNode extends OwlBotTemplateChanges { | ||
classRule = { | ||
author: 'gcf-owl-bot[bot]', | ||
// For this particular rule, we want to check a pattern and an antipattern; | ||
// we want it to start with regular commit convention, | ||
// and it should not be breaking or fix or feat | ||
titleRegex: /$(chore|build|tests|refactor)/, | ||
titleRegexExclude: /(fix|feat|breaking|!)/, | ||
bodyRegex: /PiperOrigin-RevId/, | ||
}; | ||
|
||
constructor(octokit: Octokit) { | ||
super(octokit); | ||
} | ||
|
||
public async checkPR(incomingPR: PullRequest): Promise<boolean> { | ||
const authorshipMatches = checkAuthor( | ||
this.classRule.author, | ||
incomingPR.author | ||
); | ||
|
||
const titleMatches = | ||
// We don't want it to include breaking or ! | ||
!checkTitleOrBody(incomingPR.title, this.classRule.titleRegexExclude) && | ||
// We do want it to have a conventional commit title | ||
checkTitleOrBody(incomingPR.title, this.classRule.titleRegex); | ||
|
||
let bodyMatches = true; | ||
if (incomingPR.body) { | ||
bodyMatches = checkTitleOrBody(incomingPR.body, this.classRule.bodyRegex); | ||
} | ||
|
||
reportIndividualChecks( | ||
['authorshipMatches', 'titleMatches', 'bodyMatches'], | ||
[authorshipMatches, titleMatches, !bodyMatches], | ||
incomingPR.repoOwner, | ||
incomingPR.repoName, | ||
incomingPR.prNumber | ||
); | ||
|
||
// We are looking for an antipattern, i.e., if title does not include fix or feat, and if body dodes not include PiperOrigin | ||
return authorshipMatches && titleMatches && !bodyMatches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters