Skip to content

fix: improve log messages for token creation #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 15 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function main(
core,
createAppAuth,
request,
skipTokenRevoke,
skipTokenRevoke
) {
let parsedOwner = "";
let parsedRepositoryNames = [];
Expand All @@ -33,7 +33,7 @@ export async function main(
parsedRepositoryNames = [repo];

core.info(
`owner and repositories not set, creating token for the current repository ("${repo}")`,
`Inputs 'owner' and 'repositories' are not set. Creating token for this repository (${owner}/${repo}).`
);
}

Expand All @@ -42,7 +42,7 @@ export async function main(
parsedOwner = owner;

core.info(
`repositories not set, creating token for all repositories for given owner "${owner}"`,
`Input 'repositories' is not set. Creating token for all repositories owned by ${owner}.`
);
}

Expand All @@ -52,9 +52,9 @@ export async function main(
parsedRepositoryNames = repositories;

core.info(
`owner not set, creating owner for given repositories "${repositories.join(
",",
)}" in current owner ("${parsedOwner}")`,
`No 'owner' input provided. Using default owner '${parsedOwner}' to create token for the following repositories:${repositories
.map((repo) => `\n- ${parsedOwner}/${repo}`)
.join("")}`
);
}

Expand All @@ -64,9 +64,8 @@ export async function main(
parsedRepositoryNames = repositories;

core.info(
`owner and repositories set, creating token for repositories "${repositories.join(
",",
)}" owned by "${owner}"`,
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:
${repositories.map((repo) => `\n- ${parsedOwner}/${repo}`).join("")}`
);
}

Expand All @@ -87,18 +86,18 @@ export async function main(
auth,
parsedOwner,
parsedRepositoryNames,
permissions,
permissions
),
{
onFailedAttempt: (error) => {
core.info(
`Failed to create token for "${parsedRepositoryNames.join(
",",
)}" (attempt ${error.attemptNumber}): ${error.message}`,
","
)}" (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
Expand All @@ -107,11 +106,11 @@ export async function main(
{
onFailedAttempt: (error) => {
core.info(
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`,
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`
);
},
retries: 3,
},
}
));
}

Expand Down Expand Up @@ -157,7 +156,7 @@ async function getTokenFromRepository(
auth,
parsedOwner,
parsedRepositoryNames,
permissions,
permissions
) {
// https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app
const response = await request("GET /repos/{owner}/{repo}/installation", {
Expand Down
41 changes: 29 additions & 12 deletions tests/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories set, creating token for repositories "create-github-app-token" owned by "actions"␊
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:␊
- actions/create-github-app-token␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand Down Expand Up @@ -65,7 +67,7 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories not set, creating token for the current repository ("create-github-app-token")
`Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -89,7 +91,9 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories set, creating token for repositories "failed-repo" owned by "actions"␊
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:␊
- actions/failed-repo␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -113,7 +117,7 @@ Generated by [AVA](https://avajs.dev).

> stdout

`repositories not set, creating token for all repositories for given owner "smockle"
`Input 'repositories' is not set. Creating token for all repositories owned by smockle.
Failed to create token for "smockle" (attempt 1): GitHub API not available␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -138,7 +142,9 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories set, creating token for repositories "failed-repo" owned by "actions"␊
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:␊
- actions/failed-repo␊
Failed to create token for "failed-repo" (attempt 1): GitHub API not available␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -163,7 +169,11 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories set, creating token for repositories "create-github-app-token,toolkit,checkout" owned by "actions"␊
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:␊
- actions/create-github-app-token␊
- actions/toolkit␊
- actions/checkout␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -186,7 +196,11 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories set, creating token for repositories "create-github-app-token,toolkit,checkout" owned by "actions"␊
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:␊
- actions/create-github-app-token␊
- actions/toolkit␊
- actions/checkout␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -209,7 +223,9 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories set, creating token for repositories "create-github-app-token" owned by "actions"␊
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:␊
- actions/create-github-app-token␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -232,7 +248,7 @@ Generated by [AVA](https://avajs.dev).

> stdout

`repositories not set, creating token for all repositories for given owner "actions"
`Input 'repositories' is not set. Creating token for all repositories owned by actions.
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -255,7 +271,8 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner not set, creating owner for given repositories "create-github-app-token" in current owner ("actions")␊
`No 'owner' input provided. Using default owner 'actions' to create token for the following repositories:␊
- actions/create-github-app-token␊
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -278,7 +295,7 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories not set, creating token for the current repository ("create-github-app-token")
`Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand All @@ -301,7 +318,7 @@ Generated by [AVA](https://avajs.dev).

> stdout

`owner and repositories not set, creating token for the current repository ("create-github-app-token")
`Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
Expand Down
Binary file modified tests/snapshots/index.js.snap
Binary file not shown.