Skip to content

Commit

Permalink
Build actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pngwn committed Jan 31, 2024
1 parent be74c94 commit c94a4b2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
2 changes: 2 additions & 0 deletions actions/find-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ outputs:
description: "Mergeable."
merge_sha:
description: "Merge SHA."
labels:
description: "Labels."

runs:
using: "node20"
Expand Down
84 changes: 67 additions & 17 deletions actions/find-pr/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85283,7 +85283,7 @@ function getOctokit(token, options, ...additionalPlugins) {
}
getOctokit_1 = github.getOctokit = getOctokit;
async function run() {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
const octokit = getOctokit_1(coreExports.getInput("github_token"));
const { repo, owner } = context.repo;
const outputs = {
Expand All @@ -85293,18 +85293,28 @@ async function run() {
sha: false,
mergeable: false,
merge_sha: false,
found_pr: false
found_pr: false,
labels: []
};
const open_pull_requests = await get_prs(octokit, repo, owner);
if (context.eventName === "push") {
const { source_repo, source_branch, pr_number, sha, mergeable, merge_sha } = get_pr_details_from_sha(open_pull_requests);
const {
source_repo,
source_branch,
pr_number,
sha,
mergeable,
merge_sha,
labels
} = get_pr_details_from_sha(open_pull_requests);
outputs.source_repo = source_repo || false;
outputs.source_branch = source_branch || false;
outputs.pr_number = pr_number ?? false;
outputs.sha = sha || false;
outputs.found_pr = !!(source_repo && source_branch && pr_number);
outputs.mergeable = mergeable === "MERGEABLE" ? true : false;
outputs.merge_sha = merge_sha || sha || false;
outputs.labels = labels;
} else if (context.eventName === "pull_request") {
console.log(
"PULL REQUEST",
Expand All @@ -85321,10 +85331,21 @@ async function run() {
outputs.found_pr = !!(source_repo && source_branch && pr_number);
outputs.mergeable = mergeable;
outputs.merge_sha = ((_f = context.payload.pull_request) == null ? void 0 : _f.merge_commit_sha) || outputs.sha || false;
outputs.labels = ((_h = (_g = context.payload.pull_request) == null ? void 0 : _g.labels) == null ? void 0 : _h.map(
({ name }) => name
)) || [];
} else if (context.eventName === "issue_comment") {
const { source_repo, source_branch, pr_number, sha, mergeable, merge_sha } = get_pr_details_from_number(
const {
source_repo,
source_branch,
pr_number,
sha,
mergeable,
merge_sha,
labels
} = get_pr_details_from_number(
open_pull_requests,
(_g = context.payload.issue) == null ? void 0 : _g.number
(_i = context.payload.issue) == null ? void 0 : _i.number
);
outputs.source_repo = source_repo || false;
outputs.source_branch = source_branch || false;
Expand All @@ -85333,16 +85354,25 @@ async function run() {
outputs.found_pr = !!(source_repo && source_branch && pr_number);
outputs.mergeable = mergeable === "MERGEABLE" ? true : false;
outputs.merge_sha = merge_sha || sha || false;
outputs.labels = labels;
} else if (!context.payload.workflow_run) {
coreExports.setFailed(
"This action must be run from the following events: pull_request, pull_request_target, push, workflow_run."
);
return;
}
console.log("EVENT NAME", context.eventName);
console.log("WORKFLOW EVENT TYPE", (_i = (_h = context.payload) == null ? void 0 : _h.workflow_run) == null ? void 0 : _i.event);
if (((_k = (_j = context.payload) == null ? void 0 : _j.workflow_run) == null ? void 0 : _k.event) === "pull_request" || ((_m = (_l = context.payload) == null ? void 0 : _l.workflow_run) == null ? void 0 : _m.event) === "push") {
const { source_repo, source_branch, pr_number, sha, mergeable, merge_sha } = get_pr_details_from_refs(open_pull_requests);
console.log("WORKFLOW EVENT TYPE", (_k = (_j = context.payload) == null ? void 0 : _j.workflow_run) == null ? void 0 : _k.event);
if (((_m = (_l = context.payload) == null ? void 0 : _l.workflow_run) == null ? void 0 : _m.event) === "pull_request" || ((_o = (_n = context.payload) == null ? void 0 : _n.workflow_run) == null ? void 0 : _o.event) === "push") {
const {
source_repo,
source_branch,
pr_number,
sha,
mergeable,
merge_sha,
labels
} = get_pr_details_from_refs(open_pull_requests);
console.log({
source_repo,
source_branch,
Expand All @@ -85358,17 +85388,27 @@ async function run() {
outputs.found_pr = !!(source_repo && source_branch && pr_number);
outputs.mergeable = mergeable === "MERGEABLE" ? true : false;
outputs.merge_sha = merge_sha || sha || false;
} else if (((_o = (_n = context.payload) == null ? void 0 : _n.workflow_run) == null ? void 0 : _o.event) === "issue_comment") {
const title = (_p = context.payload.workflow_run) == null ? void 0 : _p.display_title;
const { source_repo, source_branch, pr_number, sha, mergeable, merge_sha } = get_pr_details_from_title(open_pull_requests, title);
outputs.labels = labels;
} else if (((_q = (_p = context.payload) == null ? void 0 : _p.workflow_run) == null ? void 0 : _q.event) === "issue_comment") {
const title = (_r = context.payload.workflow_run) == null ? void 0 : _r.display_title;
const {
source_repo,
source_branch,
pr_number,
sha,
mergeable,
merge_sha,
labels
} = get_pr_details_from_title(open_pull_requests, title);
outputs.source_repo = source_repo || false;
outputs.source_branch = source_branch || false;
outputs.pr_number = pr_number ?? false;
outputs.sha = sha || false;
outputs.found_pr = !!(source_repo && source_branch && pr_number);
outputs.mergeable = mergeable === "MERGEABLE" ? true : false;
outputs.merge_sha = merge_sha || sha || false;
} else if ((_r = (_q = context.payload) == null ? void 0 : _q.workflow_run) == null ? void 0 : _r.event) {
outputs.labels = labels;
} else if ((_t = (_s = context.payload) == null ? void 0 : _s.workflow_run) == null ? void 0 : _t.event) {
coreExports.setFailed(
"This action can only be run on pull_request, push, or issue_comment events or workflow_run events triggered from those events."
);
Expand Down Expand Up @@ -85404,6 +85444,11 @@ async function get_prs(octokit, repo, owner) {
potentialMergeCommit {
oid
}
labels(first: 50) {
nodes {
name
}
}
}
}
}
Expand All @@ -85422,7 +85467,8 @@ const empty_pr_details = {
sha: void 0,
mergeable: void 0,
merge_sha: void 0,
title: void 0
title: void 0,
labels: []
};
function get_pr_details_from_number(pull_requests, pr_number) {
if (!pr_number)
Expand All @@ -85435,7 +85481,8 @@ function get_pr_details_from_number(pull_requests, pr_number) {
pr_number: pr.node.number,
sha: pr.node.headRefOid,
mergeable: pr.node.mergeable,
merge_sha: (_a = pr.node.potentialMergeCommit) == null ? void 0 : _a.oid
merge_sha: (_a = pr.node.potentialMergeCommit) == null ? void 0 : _a.oid,
labels: pr.node.labels.nodes.map(({ name }) => name)
};
}).find(({ pr_number: number }) => number === pr_number) || empty_pr_details;
return outputs;
Expand All @@ -85451,7 +85498,8 @@ function get_pr_details_from_sha(pull_requests) {
pr_number: pr.node.number,
sha: pr.node.headRefOid,
mergeable: pr.node.mergeable,
merge_sha: (_a2 = pr.node.potentialMergeCommit) == null ? void 0 : _a2.oid
merge_sha: (_a2 = pr.node.potentialMergeCommit) == null ? void 0 : _a2.oid,
labels: pr.node.labels.nodes.map(({ name }) => name)
};
}).find(({ sha }) => sha === head_sha) || {
source_repo: (_b = context.payload.repository) == null ? void 0 : _b.full_name,
Expand All @@ -85471,7 +85519,8 @@ function get_pr_details_from_title(pull_requests, title) {
sha: pr.node.headRefOid,
mergeable: pr.node.mergeable,
merge_sha: (_a = pr.node.potentialMergeCommit) == null ? void 0 : _a.oid,
title: pr.node.title
title: pr.node.title,
labels: pr.node.labels.nodes.map(({ name }) => name)
};
}).find(({ title: _title }) => _title === title) || empty_pr_details;
return { ...outputs, title };
Expand All @@ -85490,7 +85539,8 @@ function get_pr_details_from_refs(pull_requests) {
sha: pr.node.headRefOid,
mergeable: pr.node.mergeable,
merge_sha: (_a2 = pr.node.potentialMergeCommit) == null ? void 0 : _a2.oid,
title: pr.node.title
title: pr.node.title,
labels: pr.node.labels.nodes.map(({ name }) => name)
};
}).find(
({ source_repo: repo, source_branch: branch }) => source_repo === repo && source_branch === branch
Expand Down

0 comments on commit c94a4b2

Please sign in to comment.