Skip to content

Commit

Permalink
fix: renovate update branch areCommitsAllMadeByBots
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Jun 6, 2021
1 parent 03eecf0 commit e1a574a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dist/index-node12-dev.cjs.js

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

2 changes: 1 addition & 1 deletion dist/index-node12-dev.cjs.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/index-node12.cjs.js

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

2 changes: 1 addition & 1 deletion dist/index-node12.cjs.js.map

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/events/pr-handlers/actions/autoMergeIfPossible.ts
Expand Up @@ -8,7 +8,7 @@ import type {
PullRequestLabels,
} from '../utils/PullRequestData';
import type { ReviewflowPrContext } from '../utils/createPullRequestContext';
import { checkIfUserIsBot } from '../utils/isBotUser';
import { areCommitsAllMadeByBots } from '../utils/isBotUser';
import { updateBranch } from './updateBranch';
import { parseBody } from './utils/body/parseBody';
import hasLabelInPR from './utils/hasLabelInPR';
Expand Down Expand Up @@ -219,11 +219,7 @@ export const autoMergeIfPossible = async (
const commits = await readPullRequestCommits(context, pullRequest);

// check if has commits not made by renovate or bots like https://github.com/ornikar/shared-configs/pull/47#issuecomment-445767120
if (
commits.some(
(c) => !c.author || checkIfUserIsBot(repoContext, c.author),
)
) {
if (!areCommitsAllMadeByBots(repoContext, commits)) {
addLog('rebase-renovate', 'update branch');
if (await updateBranch(pullRequest, context, null)) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions src/events/pr-handlers/utils/isBotUser.ts
@@ -1,3 +1,4 @@
import type { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
import type { RepoContext } from '../../../context/repoContext';

export const checkIfUserIsBot = (
Expand All @@ -19,3 +20,9 @@ export const checkIfIsThisBot = (user: {
user.type === 'Bot' && user.login === `${process.env.REVIEWFLOW_NAME}[bot]`
);
};

export const areCommitsAllMadeByBots = (
repoContext: RepoContext,
commits: RestEndpointMethodTypes['pulls']['listCommits']['response']['data'],
): boolean =>
commits.every((c) => c.author && checkIfUserIsBot(repoContext, c.author));

0 comments on commit e1a574a

Please sign in to comment.