Skip to content
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

fix(auto-approve): allow Python major dependency updates #4998

Merged
merged 12 commits into from
Apr 10, 2023
6 changes: 3 additions & 3 deletions packages/auto-approve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ Below is what each process checks for:
* PythonDependency:
- Checks that the author is 'renovate-bot'
- Checks that the title of the PR matches the regexp: /^(fix|chore)\(deps\): update dependency (@?\S*) to v(\S*)$/
- Max 3 files changed in the PR
- Each file path must match one of these regexps:
- /requirements.txt$/
- /^samples/**/requirements*.txt$/
- All files must:
- Match this regexp: /^samples\/snippets\/requirements.txt$/
- Increase the non-major package version of a dependency
- Match this regexp: /requirements.txt$/
- Increase the package version of a dependency (major or nonmajor)
- Only change one dependency
- Change the dependency that was there previously, and that is on the title of the PR
* NodeDependency:
Expand Down
11 changes: 11 additions & 0 deletions packages/auto-approve/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/auto-approve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@google-cloud/secret-manager": "^4.1.1",
"ajv": "^8.11.0",
"compare-versions": "^6.0.0-rc.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the semver dependency in our tree. Can we re-use that one?

"dayjs": "^1.11.5",
"gcf-utils": "^14.2.0",
"jsonwebtoken": "^9.0.0"
Expand Down
35 changes: 12 additions & 23 deletions packages/auto-approve/src/process-checks/python/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ import {LanguageRule, File, FileRule, Process} from '../../interfaces';
import {
checkAuthor,
checkTitleOrBody,
checkFileCount,
checkFilePathsMatch,
doesDependencyChangeMatchPRTitleV2,
getVersionsV2,
runVersioningValidation,
isOneDependencyChanged,
reportIndividualChecks,
} from '../../utils-for-pr-checking';
import {Octokit} from '@octokit/rest';

import {compareVersions} from 'compare-versions';
export class PythonDependency extends Process implements LanguageRule {
classRule: {
author: string;
titleRegex?: RegExp;
maxFiles: number;
fileNameRegex?: RegExp[];
fileRules?: {
oldVersion?: RegExp;
Expand Down Expand Up @@ -66,11 +63,13 @@ export class PythonDependency extends Process implements LanguageRule {
author: 'renovate-bot',
titleRegex:
/^(fix|chore)\(deps\): update dependency (@?\S*) to v(\S*)$/,
maxFiles: 3,
fileNameRegex: [/requirements.txt$/],
fileNameRegex: [
/^samples\/.*?\/.*?requirements.*?\.txt$/,
/requirements\.txt$/,
],
fileRules: [
{
targetFileToCheck: /^samples\/snippets\/requirements.txt$/,
targetFileToCheck: /requirements.txt$/,
// This would match: fix(deps): update dependency @octokit to v1
dependencyTitle: new RegExp(
/^(fix|chore)\(deps\): update dependency (@?\S*) to v(\S*)$/
Expand Down Expand Up @@ -99,11 +98,6 @@ export class PythonDependency extends Process implements LanguageRule {
this.classRule.titleRegex
);

const fileCountMatch = checkFileCount(
this.incomingPR.fileCount,
this.classRule.maxFiles
);

const filePatternsMatch = checkFilePathsMatch(
this.incomingPR.changedFiles.map(x => x.filename),
this.classRule.fileNameRegex
Expand Down Expand Up @@ -135,8 +129,10 @@ export class PythonDependency extends Process implements LanguageRule {
this.incomingPR.title
);

const isVersionValid = runVersioningValidation(versions);
const oldNum = versions.oldMajorVersion + '.' + versions.oldMinorVersion;
const newNum = versions.newMajorVersion + '.' + versions.newMinorVersion;

const isVersionValid = compareVersions(newNum, oldNum) === 1;
const oneDependencyChanged = isOneDependencyChanged(file);

if (!(doesDependencyMatch && isVersionValid && oneDependencyChanged)) {
Expand All @@ -153,19 +149,12 @@ export class PythonDependency extends Process implements LanguageRule {
}

reportIndividualChecks(
[
'authorshipMatches',
'titleMatches',
'fileCountMatches',
'filePatternsMatch',
],
[authorshipMatches, titleMatches, fileCountMatch, filePatternsMatch],
['authorshipMatches', 'titleMatches', 'filePatternsMatch'],
[authorshipMatches, titleMatches, filePatternsMatch],
this.incomingPR.repoOwner,
this.incomingPR.repoName,
this.incomingPR.prNumber
);
return (
authorshipMatches && titleMatches && fileCountMatch && filePatternsMatch
);
return authorshipMatches && titleMatches && filePatternsMatch;
}
}
10 changes: 6 additions & 4 deletions packages/auto-approve/test/python-dependency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ describe('behavior of Python Dependency process', () => {
author: 'renovate-bot',
titleRegex:
/^(fix|chore)\(deps\): update dependency (@?\S*) to v(\S*)$/,
maxFiles: 3,
fileNameRegex: [/requirements.txt$/],
fileNameRegex: [
/^samples\/.*?\/.*?requirements.*?\.txt$/,
/requirements\.txt$/,
],
fileRules: [
{
targetFileToCheck: /^samples\/snippets\/requirements.txt$/,
targetFileToCheck: /requirements.txt$/,
// This would match: fix(deps): update dependency @octokit to v1
dependencyTitle: new RegExp(
/^(fix|chore)\(deps\): update dependency (@?\S*) to v(\S*)$/
Expand Down Expand Up @@ -154,7 +156,7 @@ describe('behavior of Python Dependency process', () => {
'@@ -1,2 +1,2 @@\n' +
' google-cloud-videointelligence==2.5.1\n' +
'-google-cloud-storage==1.42.3\n' +
'+google-cloud-storage==1.43.0',
'+google-cloud-storage==2.0.0',
},
],
'testRepoName',
Expand Down