2023-11-19 01:25:24 +01:00

41 lines
1.2 KiB
JavaScript

const core = require("@actions/core");
const github = require("@actions/github");
const { Octokit } = require("@octokit/rest");
async function run() {
try {
const branch = core.getInput("branch");
const token = core.getInput("github_token");
const octokit = new Octokit({ auth: token });
const context = github.context;
// Check for existing PRs
const { data: pullRequests } = await octokit.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${branch}`,
});
if (pullRequests.length > 0) {
console.log("A pull request already exists for this branch.");
return;
}
// Creating a new PR
const newPr = await octokit.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Your PR Title", // Customize your PR title
head: branch,
base: "main", // Change this to your default branch if it's not 'main'
body: "Your PR description", // Customize your PR description
});
console.log(`Created a new pull request: ${newPr.data.html_url}`);
} catch (error) {
core.setFailed(`Action failed with error ${error}`);
}
}
run();