-
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.
- Loading branch information
1 parent
f48a58b
commit 920cc25
Showing
3 changed files
with
59 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46744,10 +46744,10 @@ var require_github2 = __commonJS({ | |
Object.defineProperty(exports2, "__esModule", { value: true }); | ||
exports2.branchExists = branchExists; | ||
exports2.createBranch = createBranch; | ||
exports2.getBranchHeadSha = getBranchHeadSha; | ||
exports2.getDefaultBranch = getDefaultBranch; | ||
exports2.createInitialCommit = createInitialCommit; | ||
exports2.getRepoOwner = getRepoOwner; | ||
exports2.getRepoName = getRepoName; | ||
exports2.createFile = createFile; | ||
function branchExists(octokit, owner, repo, branchName) { | ||
return __awaiter2(this, void 0, void 0, function* () { | ||
try { | ||
|
@@ -46778,25 +46778,19 @@ var require_github2 = __commonJS({ | |
} | ||
}); | ||
} | ||
function getBranchHeadSha(octokit, owner, repo, branch) { | ||
function createInitialCommit(octokit, owner, repo) { | ||
return __awaiter2(this, void 0, void 0, function* () { | ||
try { | ||
const res = yield octokit.git.getRef({ | ||
owner, | ||
repo, | ||
ref: `heads/${branch}` | ||
}); | ||
const ref = res.data.object; | ||
return ref.sha; | ||
} catch (e) { | ||
return void 0; | ||
} | ||
const empty_tree_object = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; | ||
const res = yield octokit.git.createCommit({ | ||
owner, | ||
repo, | ||
message: "Initial commit", | ||
tree: empty_tree_object, | ||
parents: [] | ||
}); | ||
return res.data.sha; | ||
}); | ||
} | ||
function getDefaultBranch(ctx) { | ||
var _a; | ||
return (_a = ctx.payload.repository) === null || _a === void 0 ? void 0 : _a.default_branch; | ||
} | ||
function getRepoOwner(ctx) { | ||
var _a; | ||
return (_a = ctx.payload.repository) === null || _a === void 0 ? void 0 : _a.owner.login; | ||
|
@@ -46805,6 +46799,22 @@ var require_github2 = __commonJS({ | |
var _a; | ||
return (_a = ctx.payload.repository) === null || _a === void 0 ? void 0 : _a.name; | ||
} | ||
function createFile(octokit, owner, repo, branchName, path, content) { | ||
return __awaiter2(this, void 0, void 0, function* () { | ||
yield octokit.repos.createOrUpdateFileContents({ | ||
owner, | ||
repo, | ||
path, | ||
message: `Update by Code Limit`, | ||
branch: branchName, | ||
content: Buffer.from(content).toString("base64"), | ||
committer: { | ||
name: "Code Limit Action", | ||
email: "[email protected]" | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
|
@@ -46860,29 +46870,12 @@ function main() { | |
process.exit(1); | ||
} | ||
if (!(yield (0, github_2.branchExists)(octokit, owner, repo, "_codelimit_reports"))) { | ||
const defaultBranch = (0, github_2.getDefaultBranch)(github_1.context); | ||
if (!defaultBranch) { | ||
console.error("Could not determine default branch"); | ||
process.exit(1); | ||
} | ||
const sha = yield (0, github_2.getBranchHeadSha)(octokit, owner, repo, defaultBranch); | ||
if (!sha) { | ||
console.error("Could not determine default branch sha"); | ||
process.exit(1); | ||
} | ||
const empty_tree_object = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; | ||
const res = yield octokit.git.createCommit({ | ||
owner, | ||
repo, | ||
message: "Initial commit", | ||
tree: empty_tree_object, | ||
parents: [] | ||
}); | ||
const initialCommitSha = res.data.sha; | ||
const initialCommitSha = yield (0, github_2.createInitialCommit)(octokit, owner, repo); | ||
yield (0, github_2.createBranch)(octokit, owner, repo, "_codelimit_reports", initialCommitSha); | ||
} else { | ||
console.log("Branch _codelimit_reports already exists"); | ||
} | ||
yield (0, github_2.createFile)(octokit, owner, repo, "_codelimit_reports", "main/badge.svg", "Hello from Code Limit"); | ||
}); | ||
} | ||
main(); | ||
|
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 |
---|---|---|
|
@@ -24,20 +24,16 @@ export async function createBranch(octokit: Octokit, owner: string, repo: string | |
} | ||
} | ||
|
||
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 async function createInitialCommit(octokit: Octokit, owner: string, repo: string): Promise<string> { | ||
const empty_tree_object = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; | ||
const res = await octokit.git.createCommit({ | ||
owner: owner, | ||
repo: repo, | ||
message: 'Initial commit', | ||
tree: empty_tree_object, | ||
parents: [] | ||
}); | ||
return res.data.sha; | ||
} | ||
|
||
export function getRepoOwner(ctx: Context): string | undefined { | ||
|
@@ -46,4 +42,19 @@ export function getRepoOwner(ctx: Context): string | undefined { | |
|
||
export function getRepoName(ctx: Context): string | undefined { | ||
return ctx.payload.repository?.name | ||
} | ||
} | ||
|
||
export async function createFile(octokit: Octokit, owner: string, repo: string, branchName: string, path: string, content: string) { | ||
await octokit.repos.createOrUpdateFileContents({ | ||
owner: owner, | ||
repo: repo, | ||
path: path, | ||
message: `Update by Code Limit`, | ||
branch: branchName, | ||
content: Buffer.from(content).toString('base64'), | ||
committer: { | ||
name: 'Code Limit Action', | ||
email: '[email protected]' | ||
} | ||
}); | ||
} |