Skip to content

Commit

Permalink
Merge pull request #15 from r7kamura/src
Browse files Browse the repository at this point in the history
Seperate main.ts into some files and move them into src dir
  • Loading branch information
r7kamura authored May 30, 2024
2 parents 352dbdb + c63dd3d commit 8def81c
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 131 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: deno fmt --check **/*.ts
- run: deno lint
- run: deno fmt --check src/**/*.ts
- run: deno lint src/**/*.ts
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: deno run --allow-all main.ts
- run: deno run --allow-all src/main.ts
env:
BUMP_REQUEST_INPUTS_VERSION: ${{ inputs.version }}
GITHUB_TOKEN: ${{ inputs.github_token || github.token }}
Expand Down
128 changes: 0 additions & 128 deletions main.ts

This file was deleted.

File renamed without changes.
22 changes: 22 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { exec } from "./deps.ts";

export async function createAndPushCommit({
userName,
userEmail,
branch,
message,
files,
}: {
userName: string;
userEmail: string;
branch: string;
message: string;
files: string[];
}) {
await exec.exec("git", ["config", "user.name", userName]);
await exec.exec("git", ["config", "user.email", userEmail]);
await exec.exec("git", ["switch", "--create", branch]);
await exec.exec("git", ["add", ...files]);
await exec.exec("git", ["commit", "--message", message]);
await exec.exec("git", ["push", "--set-upstream", "origin", branch]);
}
60 changes: 60 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { github } from "./deps.ts";
import { performance } from "node:perf_hooks";

// Workaround for deno compatibility issue on undici:
// deno-lint-ignore no-explicit-any
(globalThis as any).performance = performance;

export function generateNotes({
githubToken,
owner,
repo,
tagName,
targetCommitish,
}: {
githubToken: string;
owner: string;
repo: string;
tagName: string;
targetCommitish: string;
}) {
return github.getOctokit(githubToken).request(
"POST /repos/{owner}/{repo}/releases/generate-notes",
{
owner,
repo,
tag_name: tagName,
target_commitish: targetCommitish,
},
);
}

export async function createPullRequest({
githubToken,
owner,
repo,
title,
body,
head,
base,
}: {
githubToken: string;
owner: string;
repo: string;
title: string;
body: string;
head: string;
base: string;
}) {
return await github.getOctokit(githubToken).request(
"POST /repos/{owner}/{repo}/pulls",
{
owner,
repo,
title,
body,
head,
base,
},
);
}
38 changes: 38 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { github } from "./deps.ts";
import { createAndPushCommit } from "./git.ts";
import { createPullRequest, generateNotes } from "./github.ts";

const githubToken = Deno.env.get("GITHUB_TOKEN")!;
const version = Deno.env.get("BUMP_REQUEST_INPUTS_VERSION")!;
const branch = `bump-request-${github.context.runId}`;
const title = `Change version to ${version}`;

const response = await generateNotes({
githubToken: githubToken,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tagName: `v${version}`,
targetCommitish: github.context.sha,
});

await createAndPushCommit({
userName: github.context.actor,
userEmail: `${github.context.actor}@users.noreply.github.com`,
branch,
message: title,
files: ["."],
});

await createPullRequest({
githubToken: githubToken,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
title,
body: preventMention(response.data.body),
head: branch,
base: github.context.ref,
});

function preventMention(text: string) {
return text.replace(/@/g, "@\u200B");
}

0 comments on commit 8def81c

Please sign in to comment.