Files
zigbee-OTA/src/ghw_create_pr_to_default.ts
T
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>Koen KantersNerivec
757710b4ee fix(ignore): bump typescript from 5.9.3 to 6.0.2 (#1112)
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>
2026-04-14 20:35:31 +02:00

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;
}
}