Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Apr 24, 2024
1 parent bd7356e commit a1b9003
Show file tree
Hide file tree
Showing 8 changed files with 1,843 additions and 9,960 deletions.
11,723 changes: 1,763 additions & 9,960 deletions packages/auto-approve/package-lock.json

Large diffs are not rendered by default.

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {NodeDependency} from '../src/process-checks/node/dependency';
import {NodeRelease} from '../src/process-checks/node/release';
import nock from 'nock';
const {Octokit} = require('@octokit/rest');
nock.disableNetConnect();

const octokit = new Octokit({
auth: 'mypersonalaccesstoken123',
Expand Down
1 change: 1 addition & 0 deletions packages/auto-approve/test/check-pr-V2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import sinon from 'sinon';
import {ConfigurationV2} from '../src/interfaces';

const {Octokit} = require('@octokit/rest');
nock.disableNetConnect();

const octokit = new Octokit({
auth: 'mypersonalaccesstoken123',
Expand Down
1 change: 1 addition & 0 deletions packages/auto-approve/test/check-pr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {File, ValidPr} from '../src/interfaces';
import sinon from 'sinon';

const {Octokit} = require('@octokit/rest');
nock.disableNetConnect();

const octokit = new Octokit({
auth: 'mypersonalaccesstoken123',
Expand Down
1 change: 1 addition & 0 deletions packages/auto-approve/test/get-pr-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {describe, it} from 'mocha';
import assert from 'assert';

const {Octokit} = require('@octokit/rest');
nock.disableNetConnect();

const octokit = new Octokit({
auth: 'mypersonalaccesstoken123',
Expand Down
1 change: 1 addition & 0 deletions packages/auto-approve/test/owlbot-api-changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import assert from 'assert';
import nock from 'nock';

const {Octokit} = require('@octokit/rest');
nock.disableNetConnect();

const octokit = new Octokit({
auth: 'mypersonalaccesstoken123',
Expand Down
1 change: 1 addition & 0 deletions packages/auto-approve/test/owlbot-template-changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import assert from 'assert';
import nock from 'nock';

const {Octokit} = require('@octokit/rest');
nock.disableNetConnect();

const octokit = new Octokit({
auth: 'mypersonalaccesstoken123',
Expand Down

0 comments on commit a1b9003

Please sign in to comment.