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

feat(git): Specify additional git authors to ignore #9082

Merged
merged 8 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,20 @@ If configured, Renovate bypasses its normal major/minor/patch upgrade logic and
Beware that Renovate follows tags strictly.
For example, if you are following a tag like `next` and then that stream is released as `stable` and `next` is no longer being updated then that means your dependencies also won't be getting updated.

## gitIgnoredAuthors

Specify commit authors ignored by Renovate.

If you have other bots which commit on top of Renovate PRs, you probably want Renovate to rebase those PRs instead of treating them as modified.
zharinov marked this conversation as resolved.
Show resolved Hide resolved

Example:

```json
{
"gitIgnoredAuthors": ["some-bot@example.org"]
}
```

## gitLabAutomerge

Caution (fixed in GitLab >= 12.7): when this option is enabled it is possible due to a bug in GitLab that MRs with failing pipelines might still get merged.
Expand Down
8 changes: 8 additions & 0 deletions lib/config/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,14 @@ const options: RenovateOptions[] = [
admin: true,
stage: 'global',
},
{
name: 'gitIgnoredAuthors',
description:
'Additional git authors which are ignored by Renovate. Must conform to RFC5322.',
type: 'array',
subType: 'string',
stage: 'repository',
},
{
name: 'enabledManagers',
description:
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface RenovateSharedConfig {
suppressNotifications?: string[];
timezone?: string;
unicodeEmoji?: boolean;
gitIgnoredAuthors?: string[];
}

// Config options used only within the global worker
Expand Down
8 changes: 6 additions & 2 deletions lib/util/git/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ describe('platform/git', () => {
it('should return false when branch is not found', async () => {
expect(await git.isBranchModified('renovate/not_found')).toBe(false);
});
it('should return true when author matches', async () => {
it('should return false when author matches', async () => {
expect(await git.isBranchModified('renovate/future_branch')).toBe(false);
expect(await git.isBranchModified('renovate/future_branch')).toBe(false);
});
it('should return false when custom author', async () => {
it('should return false when author is ignored', async () => {
git.setIgnoredAuthors(['custom@example.com']);
expect(await git.isBranchModified('renovate/custom_author')).toBe(false);
});
it('should return true when custom author is unknown', async () => {
expect(await git.isBranchModified('renovate/custom_author')).toBe(true);
});
});
Expand Down
13 changes: 12 additions & 1 deletion lib/util/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import URL from 'url';
import is from '@sindresorhus/is';
renovate-testing marked this conversation as resolved.
Show resolved Hide resolved
import fs from 'fs-extra';
import GitUrlParse from 'git-url-parse';
import Git, {
Expand Down Expand Up @@ -51,6 +52,7 @@ interface LocalConfig extends StorageConfig {
branchCommits: Record<string, CommitSha>;
branchIsModified: Record<string, boolean>;
branchPrefix: string;
ignoredAuthors: string[];
}

// istanbul ignore next
Expand Down Expand Up @@ -165,6 +167,7 @@ async function fetchBranchCommits(): Promise<void> {

export async function initRepo(args: StorageConfig): Promise<void> {
config = { ...args } as any;
config.ignoredAuthors = [];
config.additionalBranches = [];
config.branchIsModified = {};
git = Git(config.localDir);
Expand Down Expand Up @@ -215,6 +218,13 @@ export async function setBranchPrefix(branchPrefix: string): Promise<void> {
}
}

export function setIgnoredAuthors(ignoredAuthors?: string[]): void {
config.ignoredAuthors = [];
if (is.array(ignoredAuthors)) {
config.ignoredAuthors = ignoredAuthors;
}
renovate-testing marked this conversation as resolved.
Show resolved Hide resolved
}

export async function getSubmodules(): Promise<string[]> {
try {
return (
Expand Down Expand Up @@ -478,7 +488,8 @@ export async function isBranchModified(branchName: string): Promise<boolean> {
const { gitAuthorEmail } = config;
if (
lastAuthor === process.env.RENOVATE_LEGACY_GIT_AUTHOR_EMAIL || // remove in next major release
rarkins marked this conversation as resolved.
Show resolved Hide resolved
lastAuthor === gitAuthorEmail
lastAuthor === gitAuthorEmail ||
config.ignoredAuthors.some((ignoredAuthor) => lastAuthor === ignoredAuthor)
) {
// author matches - branch has not been modified
config.branchIsModified[branchName] = false;
Expand Down
3 changes: 2 additions & 1 deletion lib/workers/repository/init/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RenovateConfig } from '../../../config';
import { logger } from '../../../logger';
import { clone } from '../../../util/clone';
import { setBranchPrefix } from '../../../util/git';
import { setBranchPrefix, setIgnoredAuthors } from '../../../util/git';
import { checkIfConfigured } from '../configured';
import { initApis } from './apis';
import { initializeCaches } from './cache';
Expand All @@ -21,6 +21,7 @@ export async function initRepo(
config = await getRepoConfig(config);
checkIfConfigured(config);
await setBranchPrefix(config.branchPrefix);
setIgnoredAuthors(config.gitIgnoredAuthors);
renovate-testing marked this conversation as resolved.
Show resolved Hide resolved
config = await detectVulnerabilityAlerts(config);
// istanbul ignore if
if (config.printConfig) {
Expand Down