Skip to content
Open
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
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/action-github-app-token.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ inputs:
description: 'Private key for the GitHub App'
scope:
required: false
description: 'Scope of installation account'
default: ''
description: 'Scope of installation account, defaults to the owner of the repository where the workflow is executing'
default: ${{ github.repository_owner }}
outputs:
token:
description: 'Github Token for App installation'
Expand Down
37 changes: 18 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {createAppAuth} from '@octokit/auth-app';
import {Octokit} from '@octokit/rest';
import {Endpoints} from '@octokit/types';
import * as core from '@actions/core';

type listInstallationsResponse =
Endpoints['GET /app/installations']['response'];

async function run(): Promise<void> {
try {
const privateKey: string = core.getInput('private_key');
Expand All @@ -20,21 +16,24 @@ async function run(): Promise<void> {
baseUrl: process.env.GITHUB_API_URL || 'https://api.github.com',
});

const installations: listInstallationsResponse =
await appOctokit.apps.listInstallations();
let installationId = installations.data[0].id;
if (scope !== '') {
const scopedData = installations.data.find(
(item) =>
item.account &&
'login' in item.account &&
item.account?.login === scope
);
if (scopedData === undefined) {
throw new Error(`set scope is ${scope}, but installation is not found`);
}
installationId = scopedData.id;
}
const response = await appOctokit.apps
.getOrgInstallation({org: scope})
.catch(async (error) => {
if (error.status === 404) {
return await appOctokit.apps
.getUserInstallation({username: scope})
.catch((nestederror) => {
if (nestederror.status === 404) {
throw new Error(
`set scope is ${scope}, but installation is not found`
);
}
throw nestederror;
});
}
throw error;
});
const installationId = response.data.id;

// This is untyped
// See: https://github.com/octokit/core.js/blob/master/src/index.ts#L182-L183
Expand Down