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

20
dist/main.cjs vendored
View File

@@ -29923,28 +29923,30 @@ async function main(appId2, privateKey2, owner2, repositories2, core3, createApp
privateKey: privateKey2,
request: request2
});
let authentication;
let authentication, installationId, appSlug;
if (parsedRepositoryNames) {
authentication = 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}`
);
},
retries: 3
});
}));
} else {
authentication = 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}`
);
},
retries: 3
});
}));
}
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);
core3.setOutput("expiresAt", authentication.expiresAt);
@@ -29970,7 +29972,9 @@ async function getTokenFromOwner(request2, 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(request2, auth, parsedOwner, parsedRepositoryNames) {
const response = await request2("GET /repos/{owner}/{repo}/installation", {
@@ -29985,7 +29989,9 @@ async function getTokenFromRepository(request2, auth, parsedOwner, parsedReposit
installationId: response.data.id,
repositoryNames: parsedRepositoryNames.split(",")
});
return authentication;
const installationId = response.data.id;
const appSlug = response.data["app_slug"];
return { authentication, installationId, appSlug };
}
// lib/request.js