Skip to content

Commit 439152f

Browse files
authored
fix: ensure git found on trop runner (#304)
1 parent c8c9cf4 commit 439152f

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

Aptfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Heroku-24 stack doesn't include git by default.
2+
git-all

app.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"required": true
1212
}
1313
},
14-
"formation": {
15-
},
16-
"addons": [
17-
18-
],
14+
"formation": {},
15+
"addons": [],
1916
"buildpacks": [
17+
{
18+
"url": "heroku-community/apt"
19+
},
2020
{
2121
"url": "heroku/nodejs"
2222
}
2323
],
24-
"stack": "heroku-22"
24+
"stack": "heroku-24"
2525
}

src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ export const BACKPORT_REQUESTED_LABEL =
2727

2828
export const DEFAULT_BACKPORT_REVIEW_TEAM =
2929
process.env.DEFAULT_BACKPORT_REVIEW_TEAM;
30+
31+
export const VALID_BACKPORT_CHECK_NAME =
32+
process.env.BACKPORT_REQUESTED_LABEL || 'Valid Backport';

src/index.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
labelExistsOnPR,
1212
removeLabel,
1313
} from './utils/label-utils';
14-
import { CHECK_PREFIX, NO_BACKPORT_LABEL, SKIP_CHECK_LABEL } from './constants';
14+
import {
15+
CHECK_PREFIX,
16+
NO_BACKPORT_LABEL,
17+
SKIP_CHECK_LABEL,
18+
VALID_BACKPORT_CHECK_NAME,
19+
} from './constants';
1520
import { getEnvVar } from './utils/env-util';
1621
import { PRChange, PRStatus, BackportPurpose, CheckRunStatus } from './enums';
1722
import { Label } from '@octokit/webhooks-types';
@@ -28,15 +33,11 @@ import {
2833
updateBackportValidityCheck,
2934
} from './utils/checks-util';
3035
import { register } from './utils/prom';
31-
import {
32-
SimpleWebHookRepoContext,
33-
WebHookIssueContext,
34-
WebHookPR,
35-
WebHookPRContext,
36-
} from './types';
37-
38-
// Built in fetch doesn't support global-agent...
39-
// @ts-ignore
36+
import { SimpleWebHookRepoContext, WebHookPR, WebHookPRContext } from './types';
37+
38+
import { execSync } from 'child_process';
39+
40+
// @ts-ignore - builtin fetch doesn't support global-agent.
4041
delete globalThis.fetch;
4142

4243
const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
@@ -145,6 +146,12 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
145146
}
146147
};
147148

149+
const gitExists = execSync('which git').toString().trim();
150+
if (/git not found/.test(gitExists)) {
151+
robot.log('Git not found - unable to proceed with backporting');
152+
process.exit(1);
153+
}
154+
148155
/**
149156
* Checks that a PR done to `main` contains the required
150157
* backport information, i.e.: at least a `no-backport` or
@@ -154,8 +161,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
154161
* @returns
155162
*/
156163

157-
const VALID_BACKPORT_CHECK_NAME = 'Valid Backport';
158-
159164
robot.on(
160165
[
161166
'pull_request.opened',
@@ -423,7 +428,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
423428
);
424429

425430
// Backport pull requests to labeled targets when PR is merged.
426-
robot.on('pull_request.closed', async (context: WebHookPRContext) => {
431+
robot.on('pull_request.closed', async (context) => {
427432
const { pull_request: pr } = context.payload;
428433

429434
const oldPRNumbers = getPRNumbersFromPRBody(pr, true);
@@ -471,7 +476,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
471476
const TROP_COMMAND_PREFIX = '/trop ';
472477

473478
// Manually trigger backporting process on trigger comment phrase.
474-
robot.on('issue_comment.created', async (context: WebHookIssueContext) => {
479+
robot.on('issue_comment.created', async (context) => {
475480
const { issue, comment } = context.payload;
476481

477482
const isPullRequest = (i: { number: number; html_url: string }) =>

src/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fetch from 'node-fetch';
22
import * as fs from 'fs-extra';
3+
import { execSync } from 'child_process';
34
import Queue from 'queue';
45
import simpleGit from 'simple-git';
56

@@ -29,7 +30,7 @@ import {
2930
WebHookPR,
3031
WebHookRepoContext,
3132
} from './types';
32-
import { Context, Probot } from 'probot';
33+
import { Probot } from 'probot';
3334

3435
const { parse: parseDiff } = require('what-the-diff');
3536

@@ -475,6 +476,17 @@ export const backportImpl = async (
475476
}
476477
}
477478

479+
const gitExists = execSync('which git').toString().trim();
480+
if (/git not found/.test(gitExists)) {
481+
await context.octokit.issues.createComment(
482+
context.repo({
483+
body: `Git not found - unable to proceed with backporting to ${targetBranch}`,
484+
issue_number: pr.number,
485+
}),
486+
);
487+
return;
488+
}
489+
478490
const base = pr.base;
479491
const slug = `${base.repo.owner.login}/${base.repo.name}`;
480492
const bp = `backport from PR #${pr.number} to "${targetBranch}"`;

0 commit comments

Comments
 (0)