Skip to content

Commit

Permalink
release v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 4, 2020
1 parent 9d5e2f3 commit 6d1b671
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 2,452 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/publish.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

21 changes: 0 additions & 21 deletions README.md

This file was deleted.

46 changes: 46 additions & 0 deletions dist/addPullRequestComment.js
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;
31 changes: 31 additions & 0 deletions dist/getConfig.js
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;
64 changes: 64 additions & 0 deletions dist/index.js
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);
});
67 changes: 0 additions & 67 deletions src/addPullRequestComment.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/getConfig.ts

This file was deleted.

54 changes: 0 additions & 54 deletions src/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions tsconfig.json

This file was deleted.

Loading

0 comments on commit 6d1b671

Please sign in to comment.