Skip to content

Commit

Permalink
feat: base implementation for creating PRS
Browse files Browse the repository at this point in the history
  • Loading branch information
bonyuta0204 committed Nov 29, 2023
1 parent 049f470 commit 0104d82
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ description: 'Greet someone and record the time'
inputs:
src-branch: # id of input
description: "src-branch"
target-branch: # id of input
description: "src-branch"
required: true
runs:
using: 'node20'
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0"
"@actions/github": "^6.0.0",
"simple-git": "^3.21.0"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@vercel/ncc": "^0.38.1",
"prettier": "^3.1.0",
"typescript": "^5.3.2"
Expand Down
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
import core from "@actions/core";
import { getOctokit } from "@actions/github";

const srcBranch = core.getInput("src-branch");
function main() {
const token = process.env.GITHUB_TOKEN;
if (!token) {
console.error("GITHUB_TOKEN not found");
return;
}

console.log(srcBranch);
const octokit = getOctokit(token);

const srcBranch = core.getInput("src-branch");
const targetBranch = core.getInput("target-branch");

if (!srcBranch || !targetBranch) {
console.error("Source or target branch not specified");
return;
}

// Assuming the context of the action has repository information
const owner = process.env.GITHUB_REPOSITORY_OWNER || "";
const repo = (process.env.GITHUB_REPOSITORY || "").split("/")[1];

octokit.rest.pulls
.create({
owner,
repo,
title: `Merge changes from ${srcBranch} to ${targetBranch}`,
head: srcBranch,
base: targetBranch,
body: "Automatically created pull request",
})
.then((response) => {
console.log(`Pull request created: ${response.data.html_url}`);
})
.catch((error) => {
console.error(`Error creating pull request: ${error.message}`);
});
}

main();

0 comments on commit 0104d82

Please sign in to comment.