-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d5e2f3
commit 6d1b671
Showing
12 changed files
with
141 additions
and
2,452 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPullRequestBody = exports.addPullRequestComment = void 0; | ||
const request_1 = require("@octokit/request"); | ||
function addPullRequestComment({ upstream, pullNumber, accessToken, backportResponse, }) { | ||
// abort if there are 0 results and an error occurred | ||
if (backportResponse.results.length === 0) { | ||
console.log(`Not posting pull request comment because there are no results to publish`); | ||
return; | ||
} | ||
const [repoOwner, repoName] = upstream.split('/'); | ||
console.log(`Posting comment to https://github.com/${repoOwner}/${repoName}/pull/${pullNumber}`); | ||
return request_1.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { | ||
headers: { | ||
authorization: `token ${accessToken}`, | ||
}, | ||
owner: repoOwner, | ||
repo: repoName, | ||
issue_number: pullNumber, | ||
body: getPullRequestBody(backportResponse), | ||
}); | ||
} | ||
exports.addPullRequestComment = addPullRequestComment; | ||
function getPullRequestBody(backportResponse) { | ||
const header = backportResponse.success | ||
? '## 💚 Backport successful\n' | ||
: '## 💔 Backport was not successful\n'; | ||
const detailsHeader = backportResponse.results.length > 0 | ||
? backportResponse.success | ||
? 'The PR was backported to the following branches:\n' | ||
: 'The PR was attempted backported to the following branches:\n' | ||
: ''; | ||
const details = backportResponse.results | ||
.map((result) => { | ||
if (result.success) { | ||
return ` - ✅ [${result.targetBranch}](${result.pullRequestUrl})`; | ||
} | ||
return ` - ❌ ${result.targetBranch}: ${result.errorMessage}`; | ||
}) | ||
.join('\n'); | ||
const generalErrorMessage = 'errorMessage' in backportResponse | ||
? `The backport operation could not be completed due to the following error:\n${backportResponse.errorMessage}` | ||
: ''; | ||
return `${header}${detailsHeader}${details}\n${generalErrorMessage}`; | ||
} | ||
exports.getPullRequestBody = getPullRequestBody; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBackportConfig = void 0; | ||
const got_1 = __importDefault(require("got")); | ||
async function getBackportConfig({ payload, username, accessToken, }) { | ||
var _a, _b; | ||
const configUrl = `https://raw.githubusercontent.com/${payload.repository.owner.login}/${payload.repository.name}/${payload.repository.default_branch}/.backportrc.json`; | ||
try { | ||
const response = await got_1.default(configUrl); | ||
const projectConfig = JSON.parse(response.body); | ||
return { | ||
...projectConfig, | ||
username, | ||
accessToken, | ||
ci: true, | ||
pullNumber: payload.pull_request.number, | ||
//@ts-expect-error (to be fixed in https://github.com/octokit/webhooks/issues/136) | ||
assignees: [(_a = payload.pull_request.merged_by) === null || _a === void 0 ? void 0 : _a.login], | ||
}; | ||
} | ||
catch (e) { | ||
if (((_b = e.response) === null || _b === void 0 ? void 0 : _b.statusCode) === 404) { | ||
throw new Error(`No config exists for ${configUrl}`); | ||
} | ||
throw e; | ||
} | ||
} | ||
exports.getBackportConfig = getBackportConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const github_1 = require("@actions/github"); | ||
const backport = __importStar(require("backport")); | ||
const getConfig_1 = require("./getConfig"); | ||
const addPullRequestComment_1 = require("./addPullRequestComment"); | ||
const exec_1 = require("@actions/exec"); | ||
async function init() { | ||
console.log('hello1'); | ||
await exec_1.exec(`git config --global user.name "${github_1.context.actor}"`); | ||
await exec_1.exec(`git config --global user.email "github-action-${github_1.context.actor}@users.noreply.github.com"`); | ||
const payload = github_1.context.payload; | ||
try { | ||
// ignore anything but merged PRs | ||
const isMerged = payload.pull_request.merged; | ||
if (!isMerged) { | ||
console.log('PR not merged yet...'); | ||
return; | ||
} | ||
const accessToken = core.getInput('github_token', { required: true }); | ||
const username = payload.pull_request.user.login; | ||
const config = await getConfig_1.getBackportConfig({ payload, username, accessToken }); | ||
if (!config.upstream) { | ||
throw new Error('Missing upstream'); | ||
} | ||
if (!config.pullNumber) { | ||
throw new Error('Missing pull request number'); | ||
} | ||
console.log('Config', config); | ||
const backportResponse = await backport.run(config); | ||
await addPullRequestComment_1.addPullRequestComment({ | ||
upstream: config.upstream, | ||
pullNumber: config.pullNumber, | ||
accessToken, | ||
backportResponse, | ||
}); | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
init().catch((e) => { | ||
console.log('An error occurred', e); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.