feat(outputs): app-slug and installation-id (#105)

It is convenient to use `https://api.github.com/users/$app_slug[bot]` to
obtain the corresponding account ID later.
Then build `Signed-off-by: $app_slug[bot]
<$id+$app_slug[bot]@users.noreply.github.com>`.

Currently, there is no Linux environment to build test snapshot files
This commit is contained in:
沙漠之子
2024-03-02 03:18:38 +08:00
committed by GitHub
parent bf627a5a44
commit babaff4320
13 changed files with 98 additions and 28 deletions

View File

@@ -70,35 +70,36 @@ export async function main(
request,
});
let authentication;
let authentication, installationId, appSlug;
// If at least one repository is set, get installation ID from that repository
if (parsedRepositoryNames) {
authentication = 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}`
);
},
retries: 3,
});
}));
} else {
// Otherwise get the installation for the owner, which can either be an organization or a user account
authentication = 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}`
);
},
retries: 3,
});
}));
}
// Register the token with the runner as a secret to ensure it is masked in logs
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)
if (!skipTokenRevoke) {
@@ -132,7 +133,11 @@ async function getTokenFromOwner(request, auth, parsedOwner) {
type: "installation",
installationId: response.data.id,
});
return authentication;
const installationId = response.data.id;
const appSlug = response.data['app_slug'];
return { authentication, installationId, appSlug };
}
async function getTokenFromRepository(request, auth, parsedOwner, parsedRepositoryNames) {
@@ -152,5 +157,8 @@ async function getTokenFromRepository(request, auth, parsedOwner, parsedReposito
repositoryNames: parsedRepositoryNames.split(","),
});
return authentication;
}
const installationId = response.data.id;
const appSlug = response.data['app_slug'];
return { authentication, installationId, appSlug };
}