mirror of
https://github.com/Koenkk/zigbee-OTA.git
synced 2026-08-22 22:26:23 +00:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Koen Kanters <koenkanters94@gmail.com> Co-authored-by: Nerivec <62446222+Nerivec@users.noreply.github.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import assert from "node:assert";
|
|
import type * as CoreApi from "@actions/core";
|
|
import type {Octokit} from "@octokit/rest";
|
|
import type {Context} from "./types.js";
|
|
|
|
const IGNORE_OTA_WORKFLOW_LABEL = "ignore-ota-workflow";
|
|
|
|
export async function createPRToDefault(
|
|
github: Octokit,
|
|
core: typeof CoreApi,
|
|
context: Context,
|
|
fromBranchName: string,
|
|
title: string,
|
|
): Promise<void> {
|
|
assert(context.payload.repository);
|
|
assert(fromBranchName);
|
|
assert(title);
|
|
|
|
const base = context.payload.repository.default_branch;
|
|
|
|
try {
|
|
const createdPRResult = await github.rest.pulls.create({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
head: fromBranchName,
|
|
base,
|
|
title,
|
|
});
|
|
|
|
await github.rest.issues.addLabels({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: createdPRResult.data.number,
|
|
labels: [IGNORE_OTA_WORKFLOW_LABEL],
|
|
});
|
|
|
|
core.notice(`Created pull request #${createdPRResult.data.number} from branch ${fromBranchName}.`);
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
if (error.message.includes(`No commits between ${base} and ${fromBranchName}`)) {
|
|
await github.rest.git.deleteRef({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
ref: `heads/${fromBranchName}`,
|
|
});
|
|
|
|
core.notice("Nothing needed re-processing.");
|
|
|
|
// don't fail if no commits
|
|
return;
|
|
}
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
}
|