Skip to content

Commit

Permalink
fix: renovate adds labels after opening pr
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed May 25, 2019
1 parent ed6bd2f commit 5bc57e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
20 changes: 20 additions & 0 deletions src/pr-handlers/actions/autoApproveAndAutoMerge.ts
@@ -0,0 +1,20 @@
import Webhooks from '@octokit/webhooks';
import { Context } from 'probot';
import { RepoContext } from '../../context/repoContext';
import { autoMergeIfPossible } from './autoMergeIfPossible';

export const autoApproveAndAutoMerge = async (
context: Context<Webhooks.WebhookPayloadPullRequest>,
repoContext: RepoContext,
): Promise<void> => {
// const autoMergeLabel = repoContext.labels['merge/automerge'];
const codeApprovedLabel = repoContext.labels['code/approved'];
const prLabels = context.payload.pull_request.labels;
if (prLabels.find((l): boolean => l.id === codeApprovedLabel.id)) {
await context.github.pulls.createReview(
context.issue({ event: 'APPROVE' }),
);
}

await autoMergeIfPossible(context, repoContext);
};
13 changes: 12 additions & 1 deletion src/pr-handlers/labelsChanged.ts
Expand Up @@ -2,15 +2,26 @@ import { Application } from 'probot';
import { handlerPullRequestChange } from './utils';
import { autoMergeIfPossible } from './actions/autoMergeIfPossible';
import { updateStatusCheckFromLabels } from './actions/updateStatusCheckFromLabels';
import { autoApproveAndAutoMerge } from './actions/autoApproveAndAutoMerge';

export default function labelsChanged(app: Application): void {
app.on(
['pull_request.labeled', 'pull_request.unlabeled'],
async (context) => {
const sender = context.payload.sender;
if (sender.type === 'Bot') return;
const fromRenovate =
sender.type === 'Bot' &&
context.payload.pull_request.head.ref.startsWith('renovate/');

if (sender.type === 'Bot' && !fromRenovate) {
return;
}

await handlerPullRequestChange(context, async (repoContext) => {
if (fromRenovate) {
return autoApproveAndAutoMerge(context, repoContext);
}

const label = context.payload.label;
if (repoContext.protectedLabelIds.includes(label.id)) {
if (context.payload.action === 'labeled') {
Expand Down
22 changes: 2 additions & 20 deletions src/pr-handlers/opened.ts
@@ -1,27 +1,9 @@
import Webhooks from '@octokit/webhooks';
import { Application, Context } from 'probot';
import { RepoContext } from '../context/repoContext';
import { Application } from 'probot';
import { createHandlerPullRequestChange } from './utils';
import { autoAssignPRToCreator } from './actions/autoAssignPRToCreator';
import { editOpenedPR } from './actions/editOpenedPR';
import { updateReviewStatus } from './actions/updateReviewStatus';
import { autoMergeIfPossible } from './actions/autoMergeIfPossible';

const autoApproveAndAutoMerge = async (
context: Context<Webhooks.WebhookPayloadPullRequest>,
repoContext: RepoContext,
): Promise<void> => {
// const autoMergeLabel = repoContext.labels['merge/automerge'];
const codeApprovedLabel = repoContext.labels['code/approved'];
const prLabels = context.payload.pull_request.labels;
if (prLabels.find((l): boolean => l.id === codeApprovedLabel.id)) {
await context.github.pulls.createReview(
context.issue({ event: 'APPROVE' }),
);
}

await autoMergeIfPossible(context, repoContext);
};
import { autoApproveAndAutoMerge } from './actions/autoApproveAndAutoMerge';

export default function opened(app: Application): void {
app.on(
Expand Down

0 comments on commit 5bc57e0

Please sign in to comment.