-
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
c0b814f
commit bfe92c6
Showing
2 changed files
with
39 additions
and
4 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 |
---|---|---|
|
@@ -46747,6 +46747,7 @@ var require_github2 = __commonJS({ | |
exports2.createInitialCommit = createInitialCommit; | ||
exports2.getRepoOwner = getRepoOwner; | ||
exports2.getRepoName = getRepoName; | ||
exports2.getIdentity = getIdentity; | ||
exports2.createOrUpdateFile = createOrUpdateFile; | ||
function branchExists(octokit, owner, repo, branchName) { | ||
return __awaiter2(this, void 0, void 0, function* () { | ||
|
@@ -46799,6 +46800,23 @@ var require_github2 = __commonJS({ | |
var _a; | ||
return (_a = ctx.payload.repository) === null || _a === void 0 ? void 0 : _a.name; | ||
} | ||
function getIdentity(octokit) { | ||
return __awaiter2(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
const identityQuery = ` | ||
query { | ||
viewer { | ||
databaseId | ||
login | ||
} | ||
} | ||
`; | ||
const queryResult = yield octokit.graphql(identityQuery); | ||
const databaseId = (_a = queryResult === null || queryResult === void 0 ? void 0 : queryResult.viewer) === null || _a === void 0 ? void 0 : _a.databaseId; | ||
const login = (_b = queryResult === null || queryResult === void 0 ? void 0 : queryResult.viewer) === null || _b === void 0 ? void 0 : _b.databaseId; | ||
return { name: login, email: `${databaseId}+${login}@users.noreply.github.com` }; | ||
}); | ||
} | ||
function createOrUpdateFile(octokit, owner, repo, branchName, path, content) { | ||
return __awaiter2(this, void 0, void 0, function* () { | ||
let sha = void 0; | ||
|
@@ -46815,6 +46833,7 @@ var require_github2 = __commonJS({ | |
sha = res.data.sha; | ||
} catch (e) { | ||
} | ||
const identity = yield getIdentity(octokit); | ||
yield octokit.repos.createOrUpdateFileContents({ | ||
owner, | ||
repo, | ||
|
@@ -46824,8 +46843,8 @@ var require_github2 = __commonJS({ | |
branch: branchName, | ||
content: Buffer.from(content).toString("base64"), | ||
committer: { | ||
name: "Code Limit Action", | ||
email: "[email protected]" | ||
name: identity.name, | ||
email: identity.email | ||
} | ||
}); | ||
}); | ||
|
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 |
---|---|---|
|
@@ -44,6 +44,21 @@ export function getRepoName(ctx: Context): string | undefined { | |
return ctx.payload.repository?.name | ||
} | ||
|
||
export async function getIdentity(octokit: Octokit): Promise<{ name: string, email: string }> { | ||
const identityQuery = ` | ||
query { | ||
viewer { | ||
databaseId | ||
login | ||
} | ||
} | ||
`; | ||
const queryResult: any = await octokit.graphql(identityQuery); | ||
const databaseId = queryResult?.viewer?.databaseId; | ||
const login = queryResult?.viewer?.databaseId; | ||
return {name: login, email: `${databaseId}+${login}@users.noreply.github.com`}; | ||
} | ||
|
||
export async function createOrUpdateFile(octokit: Octokit, owner: string, repo: string, branchName: string, path: string, content: string) { | ||
let sha = undefined; | ||
try { | ||
|
@@ -60,6 +75,7 @@ export async function createOrUpdateFile(octokit: Octokit, owner: string, repo: | |
} catch (e) { | ||
/* do nothing */ | ||
} | ||
const identity = await getIdentity(octokit); | ||
await octokit.repos.createOrUpdateFileContents({ | ||
owner: owner, | ||
repo: repo, | ||
|
@@ -69,8 +85,8 @@ export async function createOrUpdateFile(octokit: Octokit, owner: string, repo: | |
branch: branchName, | ||
content: Buffer.from(content).toString('base64'), | ||
committer: { | ||
name: 'Code Limit Action', | ||
email: '[email protected]' | ||
name: identity.name, | ||
email: identity.email | ||
} | ||
}); | ||
} |