Skip to content

Commit

Permalink
Merge pull request #71 from HalleyAssist/master
Browse files Browse the repository at this point in the history
boolean input fix, improved language, auto detect parent
  • Loading branch information
tgymnich authored Oct 30, 2021
2 parents 1d0ea3f + bf7836b commit 6e66034
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checkin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
check_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2.3.5

- name: "npm ci"
run: npm ci
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2.3.5
- uses: tgymnich/publish-github-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ inputs:
pr_title:
description: 'The title of the pull request'
required: false
default: 'Fork Sync'
default: 'Fork Sync: Update from parent repository'
pr_message:
description: 'The message in the pull request'
required: false
ignore_fail:
description: 'ignore Exceptions'
description: 'Ignore Exceptions'
required: false
default: false
auto_approve:
description: 'Automatically approve pull request before merge'
required: false
default: false
auto_merge:
description: 'Automatically merge the pull request'
required: false
default: true
retries:
description: 'Retry count'
required: false
Expand Down
30 changes: 23 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ const context = Github.context;
const MyOctokit = Octokit.plugin(retry);
function run() {
return __awaiter(this, void 0, void 0, function* () {
const owner = core.getInput('owner', { required: false }) || context.repo.owner;
let owner = core.getInput('owner', { required: false }) || context.repo.owner;
let repo = context.repo.repo;
const base = core.getInput('base', { required: false });
const head = core.getInput('head', { required: false });
const mergeMethod = core.getInput('merge_method', { required: false });
const prTitle = core.getInput('pr_title', { required: false });
const prMessage = core.getInput('pr_message', { required: false });
const ignoreFail = core.getInput('ignore_fail', { required: false });
const autoApprove = core.getInput('auto_approve', { required: false });
const ignoreFail = core.getBooleanInput('ignore_fail', { required: false });
const autoApprove = core.getBooleanInput('auto_approve', { required: false });
const autoMerge = core.getBooleanInput('auto_merge', { required: false });
const retries = parseInt(core.getInput('retries', { required: false })) || 4;
const retryAfter = parseInt(core.getInput('retry_after', { required: false })) || 60;
const octokit = new MyOctokit({
Expand All @@ -54,14 +56,24 @@ function run() {
retryAfter,
},
});
let r = yield octokit.rest.repos.get({
owner,
repo,
});
if (r && r.data && r.data.parent) {
owner = r.data.parent.owner.login || owner;
repo = r.data.parent.name || repo;
}
try {
let pr = yield octokit.pulls.create({ owner: context.repo.owner, repo: context.repo.repo, title: prTitle, head: owner + ':' + head, base: base, body: prMessage, maintainer_can_modify: false });
let pr = yield octokit.pulls.create({ owner: context.repo.owner, repo, title: prTitle, head: owner + ':' + head, base: base, body: prMessage, maintainer_can_modify: false });
yield delay(20);
if (autoApprove) {
yield octokit.pulls.createReview({ owner: context.repo.owner, repo: context.repo.repo, pull_number: pr.data.number, event: "COMMENT", body: "Auto approved" });
yield octokit.pulls.createReview({ owner: context.repo.owner, repo: context.repo.repo, pull_number: pr.data.number, event: "APPROVE" });
yield octokit.pulls.createReview({ owner: context.repo.owner, repo, pull_number: pr.data.number, event: "COMMENT", body: "Auto approved" });
yield octokit.pulls.createReview({ owner: context.repo.owner, repo, pull_number: pr.data.number, event: "APPROVE" });
}
if (autoMerge) {
yield octokit.pulls.merge({ owner: context.repo.owner, repo, pull_number: pr.data.number, merge_method: mergeMethod });
}
yield octokit.pulls.merge({ owner: context.repo.owner, repo: context.repo.repo, pull_number: pr.data.number, merge_method: mergeMethod });
}
catch (error) {
if (error.request.request.retryCount) {
Expand All @@ -70,6 +82,10 @@ function run() {
if (!!error.errors && !!error.errors[0] && !!error.errors[0].message && error.errors[0].message.startsWith('No commits between')) {
console.log('No commits between ' + context.repo.owner + ':' + base + ' and ' + owner + ':' + head);
}
else if (!!error.errors && !!error.errors[0] && !!error.errors[0].message && error.errors[0].message.startsWith('A pull request already exists for')) {
// we were already done
console.log(error.errors[0].message);
}
else {
if (!ignoreFail) {
core.setFailed(`Failed to create or merge pull request: ${error !== null && error !== void 0 ? error : "[n/a]"}`);
Expand Down
Loading

0 comments on commit 6e66034

Please sign in to comment.