-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from r7kamura/src
Seperate main.ts into some files and move them into src dir
- Loading branch information
Showing
7 changed files
with
123 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |