Skip to content

Commit

Permalink
chore: 🚧 Use correct identity
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Dec 2, 2024
1 parent c0b814f commit bfe92c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
23 changes: 21 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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* () {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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
}
});
});
Expand Down
20 changes: 18 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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
}
});
}

0 comments on commit bfe92c6

Please sign in to comment.