-
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.
chore: 🚧 Create report branch if it does not exist
- Loading branch information
1 parent
55854f6
commit 4550117
Showing
2 changed files
with
102 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {Octokit} from "@octokit/action"; | ||
import {Context} from "@actions/github/lib/context"; | ||
|
||
export async function branchExists(octokit: Octokit, owner: string, repo: string, branchName: string) { | ||
try { | ||
await octokit.git.getRef({ | ||
owner: owner, repo: repo, ref: `heads/${branchName}` | ||
}) | ||
return true | ||
} catch (err) { | ||
return false | ||
} | ||
} | ||
|
||
export async function createBranch(octokit: Octokit, owner: string, repo: string, branchName: string, sha: string) { | ||
try { | ||
const res = await octokit.git.createRef({ | ||
owner: owner, repo: repo, ref: `refs/heads/${branchName}`, sha: sha | ||
}) | ||
console.log(`Branch created: ${branchName}`); | ||
return res | ||
} catch (e: any) { | ||
console.error(`Could not create branch \`${branchName}\` due to: ${e.message}`); | ||
} | ||
} | ||
|
||
export async function getBranchHeadSha(octokit: Octokit, owner: string, repo: string, branch: string) { | ||
try { | ||
const res = await octokit.git.getRef({ | ||
owner: owner, repo: repo, ref: `heads/${branch}` | ||
}) | ||
const ref = res.data.object | ||
return ref.sha | ||
} catch (e) { | ||
return undefined | ||
} | ||
} | ||
|
||
export function getDefaultBranch(ctx: Context): string | undefined { | ||
return ctx.payload.repository?.default_branch | ||
} | ||
|
||
export function getRepoOwner(ctx: Context): string | undefined { | ||
return ctx.payload.repository?.owner.login | ||
} | ||
|
||
export function getRepoName(ctx: Context): string | undefined { | ||
return ctx.payload.repository?.name | ||
} |