Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add GitHub App's installation Id output
  • Loading branch information
maboloshi committed Feb 22, 2024
commit 36eed156b767c6d94c65f95b2557bbad3805a966
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ jobs:

GitHub App installation access token.

### `installation-id`

GitHub App's installation Id.

### `app-slug`

GitHub App's slug.
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ inputs:
outputs:
token:
description: "GitHub installation access token"
installation-id:
description: "GitHub App's installation Id"
app-slug:
description: "GitHub App's slug"
runs:
Expand Down
13 changes: 8 additions & 5 deletions dist/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27700,9 +27700,9 @@ async function main(appId2, privateKey2, owner2, repositories2, core3, createApp
privateKey: privateKey2,
request: request2
});
let authentication, appSlug;
let authentication, installationId, appSlug;
if (parsedRepositoryNames) {
({ authentication, appSlug } = await pRetry(() => getTokenFromRepository(request2, auth, parsedOwner, parsedRepositoryNames), {
({ authentication, installationId, appSlug } = await pRetry(() => getTokenFromRepository(request2, auth, parsedOwner, parsedRepositoryNames), {
onFailedAttempt: (error) => {
core3.info(
`Failed to create token for "${parsedRepositoryNames}" (attempt ${error.attemptNumber}): ${error.message}`
Expand All @@ -27711,7 +27711,7 @@ async function main(appId2, privateKey2, owner2, repositories2, core3, createApp
retries: 3
}));
} else {
({ authentication, appSlug } = await pRetry(() => getTokenFromOwner(request2, auth, parsedOwner), {
({ authentication, installationId, appSlug } = await pRetry(() => getTokenFromOwner(request2, auth, parsedOwner), {
onFailedAttempt: (error) => {
core3.info(
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`
Expand All @@ -27722,6 +27722,7 @@ async function main(appId2, privateKey2, owner2, repositories2, core3, createApp
}
core3.setSecret(authentication.token);
core3.setOutput("token", authentication.token);
core3.setOutput("installation-id", installationId);
core3.setOutput("app-slug", appSlug);
if (!skipTokenRevoke2) {
core3.saveState("token", authentication.token);
Expand All @@ -27748,8 +27749,9 @@ async function getTokenFromOwner(request2, auth, parsedOwner) {
type: "installation",
installationId: response.data.id
});
const installationId = response.data.id;
const appSlug = response.data["app_slug"];
return { authentication, appSlug };
return { authentication, installationId, appSlug };
}
async function getTokenFromRepository(request2, auth, parsedOwner, parsedRepositoryNames) {
const response = await request2("GET /repos/{owner}/{repo}/installation", {
Expand All @@ -27764,8 +27766,9 @@ async function getTokenFromRepository(request2, auth, parsedOwner, parsedReposit
installationId: response.data.id,
repositoryNames: parsedRepositoryNames.split(",")
});
const installationId = response.data.id;
const appSlug = response.data["app_slug"];
return { authentication, appSlug };
return { authentication, installationId, appSlug };
}

// lib/request.js
Expand Down
13 changes: 8 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export async function main(
request,
});

let authentication, appSlug;
let authentication, installationId, appSlug;
// If at least one repository is set, get installation ID from that repository

if (parsedRepositoryNames) {
({ authentication, appSlug } = await pRetry(() => getTokenFromRepository(request, auth, parsedOwner, parsedRepositoryNames), {
({ authentication, installationId, appSlug } = await pRetry(() => getTokenFromRepository(request, auth, parsedOwner, parsedRepositoryNames), {
onFailedAttempt: (error) => {
core.info(
`Failed to create token for "${parsedRepositoryNames}" (attempt ${error.attemptNumber}): ${error.message}`
Expand All @@ -84,7 +84,7 @@ export async function main(
}));
} else {
// Otherwise get the installation for the owner, which can either be an organization or a user account
({ authentication, appSlug } = await pRetry(() => getTokenFromOwner(request, auth, parsedOwner), {
({ authentication, installationId, appSlug } = await pRetry(() => getTokenFromOwner(request, auth, parsedOwner), {
onFailedAttempt: (error) => {
core.info(
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`
Expand All @@ -98,6 +98,7 @@ export async function main(
core.setSecret(authentication.token);

core.setOutput("token", authentication.token);
core.setOutput("installation-id", installationId);
core.setOutput("app-slug", appSlug);

// Make token accessible to post function (so we can invalidate it)
Expand Down Expand Up @@ -133,9 +134,10 @@ async function getTokenFromOwner(request, auth, parsedOwner) {
installationId: response.data.id,
});

const installationId = response.data.id;
const appSlug = response.data['app_slug'];

return { authentication, appSlug };
return { authentication, installationId, appSlug };
}

async function getTokenFromRepository(request, auth, parsedOwner, parsedRepositoryNames) {
Expand All @@ -155,7 +157,8 @@ async function getTokenFromRepository(request, auth, parsedOwner, parsedReposito
repositoryNames: parsedRepositoryNames.split(","),
});

const installationId = response.data.id;
const appSlug = response.data['app_slug'];

return { authentication, appSlug };
return { authentication, installationId, appSlug };
}
18 changes: 18 additions & 0 deletions tests/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand Down Expand Up @@ -88,6 +90,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -106,6 +110,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -124,6 +130,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -142,6 +150,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -161,6 +171,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -179,6 +191,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -197,6 +211,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand All @@ -215,6 +231,8 @@ Generated by [AVA](https://avajs.dev).
␍␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
::set-output name=installation-id::123456␍␊
␍␊
::set-output name=app-slug::github-actions␍␊
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␍␊
␍␊
Expand Down
Binary file modified tests/snapshots/index.js.snap
Binary file not shown.