Skip to content

Commit

Permalink
feat(git): Specify additional git authors to ignore (#9082)
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate-testing committed Mar 14, 2021
1 parent 717e4e6 commit ea0bcdd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
16 changes: 16 additions & 0 deletions docs/usage/configuration-options.md
Expand Up @@ -635,6 +635,22 @@ 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.

By default, Renovate will treat any PR as modified if another git author has added to the branch.
When a PR is considered modified, Renovate won't perform any further commits such as if it's conflicted or needs a version update.
If you have other bots which commit on top of Renovate PRs, and don't want Renovate to treat these PRs as modified, then add the other git author(s) to `gitIgnoredAuthors`.

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
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
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
16 changes: 11 additions & 5 deletions lib/util/git/index.spec.ts
Expand Up @@ -73,7 +73,7 @@ describe('platform/git', () => {
gitAuthorName: 'Jest',
gitAuthorEmail: 'Jest@example.com',
});
await git.setBranchPrefix('renovate/');
await git.setUserRepoConfig({ branchPrefix: 'renovate/' });
await git.syncGit();
});

Expand Down Expand Up @@ -145,11 +145,17 @@ 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 () => {
await git.setUserRepoConfig({
gitIgnoredAuthors: ['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 Expand Up @@ -389,7 +395,7 @@ describe('platform/git', () => {
url: base.path,
});

await git.setBranchPrefix('renovate/');
await git.setUserRepoConfig({ branchPrefix: 'renovate/' });
expect(git.branchExists('renovate/test')).toBe(true);

await git.initRepo({
Expand All @@ -400,7 +406,7 @@ describe('platform/git', () => {
await repo.checkout('renovate/test');
await repo.commit('past message3', ['--amend']);

await git.setBranchPrefix('renovate/');
await git.setUserRepoConfig({ branchPrefix: 'renovate/' });
expect(git.branchExists('renovate/test')).toBe(true);
});

Expand Down
16 changes: 14 additions & 2 deletions lib/util/git/index.ts
Expand Up @@ -9,6 +9,7 @@ import Git, {
} from 'simple-git';
import { join } from 'upath';
import { configFileNames } from '../../config/app-strings';
import { RenovateConfig } from '../../config/types';
import {
CONFIG_VALIDATION,
REPOSITORY_DISABLED,
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 @@ -200,7 +203,7 @@ async function cleanLocalBranches(): Promise<void> {
* When we initially clone, we clone only the default branch so how no knowledge of other branches existing.
* By calling this function once the repo's branchPrefix is known, we can fetch all of Renovate's branches in one command.
*/
export async function setBranchPrefix(branchPrefix: string): Promise<void> {
async function setBranchPrefix(branchPrefix: string): Promise<void> {
config.branchPrefix = branchPrefix;
// If the repo is already cloned then set branchPrefix now, otherwise it will be called again during syncGit()
if (gitInitialized) {
Expand All @@ -215,6 +218,14 @@ export async function setBranchPrefix(branchPrefix: string): Promise<void> {
}
}

export async function setUserRepoConfig({
branchPrefix,
gitIgnoredAuthors,
}: RenovateConfig): Promise<void> {
await setBranchPrefix(branchPrefix);
config.ignoredAuthors = gitIgnoredAuthors ?? [];
}

export async function getSubmodules(): Promise<string[]> {
try {
return (
Expand Down Expand Up @@ -478,7 +489,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
lastAuthor === gitAuthorEmail
lastAuthor === gitAuthorEmail ||
config.ignoredAuthors.some((ignoredAuthor) => lastAuthor === ignoredAuthor)
) {
// author matches - branch has not been modified
config.branchIsModified[branchName] = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/index.ts
@@ -1,7 +1,7 @@
import { RenovateConfig } from '../../../config';
import { logger } from '../../../logger';
import { clone } from '../../../util/clone';
import { setBranchPrefix } from '../../../util/git';
import { setUserRepoConfig } from '../../../util/git';
import { checkIfConfigured } from '../configured';
import { initApis } from './apis';
import { initializeCaches } from './cache';
Expand All @@ -20,7 +20,7 @@ export async function initRepo(
config = await initApis(config);
config = await getRepoConfig(config);
checkIfConfigured(config);
await setBranchPrefix(config.branchPrefix);
await setUserRepoConfig(config);
config = await detectVulnerabilityAlerts(config);
// istanbul ignore if
if (config.printConfig) {
Expand Down

0 comments on commit ea0bcdd

Please sign in to comment.