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 3 commits
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
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
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
26 changes: 21 additions & 5 deletions lib/util/git/index.spec.ts
Expand Up @@ -3,6 +3,16 @@ import Git from 'simple-git';
import tmp from 'tmp-promise';
import * as git from '.';

function userConfig(
config: Partial<git.UserRepoConfig> = {}
): git.UserRepoConfig {
return {
branchPrefix: 'renovate/',
gitIgnoredAuthors: [],
...config,
};
}

describe('platform/git', () => {
jest.setTimeout(15000);

Expand Down Expand Up @@ -73,7 +83,7 @@ describe('platform/git', () => {
gitAuthorName: 'Jest',
gitAuthorEmail: 'Jest@example.com',
});
await git.setBranchPrefix('renovate/');
await git.setUserRepoConfig(userConfig());
await git.syncGit();
});

Expand Down Expand Up @@ -145,11 +155,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(
userConfig({ 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 +405,7 @@ describe('platform/git', () => {
url: base.path,
});

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

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

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

Expand Down
24 changes: 22 additions & 2 deletions lib/util/git/index.ts
Expand Up @@ -51,6 +51,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 +166,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 +202,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> {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
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 +217,23 @@ export async function setBranchPrefix(branchPrefix: string): Promise<void> {
}
}

function setIgnoredAuthors(ignoredAuthors?: string[]): void {
config.ignoredAuthors = ignoredAuthors ?? [];
}
viceice marked this conversation as resolved.
Show resolved Hide resolved

export interface UserRepoConfig {
branchPrefix: string;
gitIgnoredAuthors: string[];
}

export async function setUserRepoConfig({
branchPrefix,
gitIgnoredAuthors,
}: Partial<UserRepoConfig>): Promise<void> {
viceice marked this conversation as resolved.
Show resolved Hide resolved
await setBranchPrefix(branchPrefix);
setIgnoredAuthors(gitIgnoredAuthors);
}

export async function getSubmodules(): Promise<string[]> {
try {
return (
Expand Down Expand Up @@ -478,7 +497,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
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