From ff7b372e41c7a45bd2e136bfcfce13e72ceaf36f Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 23 Aug 2024 10:23:39 +0200 Subject: [PATCH] fix: ensure git found on trop runner --- Aptfile | 2 ++ app.json | 11 +++++------ src/index.ts | 6 +++--- src/utils.ts | 14 +++++++++++++- 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 Aptfile diff --git a/Aptfile b/Aptfile new file mode 100644 index 0000000..054b0ae --- /dev/null +++ b/Aptfile @@ -0,0 +1,2 @@ +# Heroku-24 stack doesn't include git by default. +git-all \ No newline at end of file diff --git a/app.json b/app.json index 7ca7f21..282c569 100644 --- a/app.json +++ b/app.json @@ -11,15 +11,14 @@ "required": true } }, - "formation": { - }, - "addons": [ - - ], + "formation": {}, + "addons": [], "buildpacks": [ { "url": "heroku/nodejs" + }, { + "url": "heroku-community/apt" } ], - "stack": "heroku-22" + "stack": "heroku-24" } diff --git a/src/index.ts b/src/index.ts index 12bdbb9..6977372 100644 --- a/src/index.ts +++ b/src/index.ts @@ -370,7 +370,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { 'pull_request.unlabeled', 'pull_request.synchronize', ], - async (context) => { + async (context: WebHookPRContext) => { const pr = context.payload.pull_request; if (pr.base.ref !== pr.base.repo.default_branch) { @@ -423,7 +423,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { ); // Backport pull requests to labeled targets when PR is merged. - robot.on('pull_request.closed', async (context: WebHookPRContext) => { + robot.on('pull_request.closed', async (context) => { const { pull_request: pr } = context.payload; const oldPRNumbers = getPRNumbersFromPRBody(pr, true); @@ -471,7 +471,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { const TROP_COMMAND_PREFIX = '/trop '; // Manually trigger backporting process on trigger comment phrase. - robot.on('issue_comment.created', async (context: WebHookIssueContext) => { + robot.on('issue_comment.created', async (context) => { const { issue, comment } = context.payload; const isPullRequest = (i: { number: number; html_url: string }) => diff --git a/src/utils.ts b/src/utils.ts index cf205e2..18e021b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import fetch from 'node-fetch'; import * as fs from 'fs-extra'; +import { execSync } from 'child_process'; import Queue from 'queue'; import simpleGit from 'simple-git'; @@ -29,7 +30,7 @@ import { WebHookPR, WebHookRepoContext, } from './types'; -import { Context, Probot } from 'probot'; +import { Probot } from 'probot'; const { parse: parseDiff } = require('what-the-diff'); @@ -475,6 +476,17 @@ export const backportImpl = async ( } } + const gitExists = execSync('which git').toString().trim(); + if (/git not found/.test(gitExists)) { + await context.octokit.issues.createComment( + context.repo({ + body: `Git not found - unable to proceed with backporting to ${targetBranch}`, + issue_number: pr.number, + }), + ); + return; + } + const base = pr.base; const slug = `${base.repo.owner.login}/${base.repo.name}`; const bp = `backport from PR #${pr.number} to "${targetBranch}"`;