Skip to content

Commit

Permalink
Remove app login check
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Harding <[email protected]>
  • Loading branch information
klutchell committed Nov 25, 2024
1 parent 281a188 commit 4a5ea70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export default (app: Probot) => {
return;
}

const client = await app.auth(); // Gets an authenticated Octokit client
const { data: appDetails } = await client.apps.getAuthenticated(); // Retrieves details about the authenticated app
// app.log.info(JSON.stringify(appDetails, null, 2)); // Logs details about the app
// const client = await app.auth(); // Gets an authenticated Octokit client
// const { data: appDetails } = await client.apps.getAuthenticated(); // Retrieves details about the authenticated app
// // app.log.info(JSON.stringify(appDetails, null, 2)); // Logs details about the app

const bypassActors = process.env.BYPASS_ACTORS?.split(',') ?? [];

Expand All @@ -45,7 +45,7 @@ export default (app: Probot) => {
return context.octokit.request(`POST ${callbackUrl}`, {
environment_name: environment,
state: 'approved',
comment: `Approved by ${appDetails.slug} on behalf of ${deployment.creator.login}`,
comment: `Auto-approved for ${deployment.creator.login}`,
});
});

Expand All @@ -70,9 +70,9 @@ export default (app: Probot) => {
return;
}

const client = await app.auth(); // Gets an authenticated Octokit client
const { data: appDetails } = await client.apps.getAuthenticated(); // Retrieves details about the authenticated app
// app.log.info(JSON.stringify(appDetails, null, 2)); // Logs details about the app
// const client = await app.auth(); // Gets an authenticated Octokit client
// const { data: appDetails } = await client.apps.getAuthenticated(); // Retrieves details about the authenticated app
// // app.log.info(JSON.stringify(appDetails, null, 2)); // Logs details about the app

// let approved = false;

Expand Down Expand Up @@ -108,7 +108,7 @@ export default (app: Probot) => {
run.id,
environment,
'approved',
`Approved by ${appDetails.slug} via review comment: ${review.html_url}`,
`Approved by [${review.user.login}](${review.user.html_url}) via review comment: ${review.html_url}`,
);
// approved = true;
}
Expand Down
28 changes: 3 additions & 25 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ describe('GitHub Deployment App', () => {
describe('deployment_protection_rule.requested', () => {
test('approves deployment for allowed user', async () => {
const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' })
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.post(
Expand Down Expand Up @@ -141,54 +139,40 @@ describe('GitHub Deployment App', () => {
},
};

const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' });

await probot.receive({
name: 'deployment_protection_rule',
payload,
});

expect(mock.pendingMocks()).toStrictEqual([]);
expect(nock.pendingMocks()).toStrictEqual([]);
});

test('handles undefined BYPASS_ACTORS', async () => {
process.env.BYPASS_ACTORS = '';

const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' });

await probot.receive({
name: 'deployment_protection_rule',
payload: testFixtures.deployment_protection_rule,
});

expect(mock.pendingMocks()).toStrictEqual([]);
expect(nock.pendingMocks()).toStrictEqual([]);
});

test('handles defined bypass actors with multiple values', async () => {
process.env.BYPASS_ACTORS = '1,2,3';

const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' });

await probot.receive({
name: 'deployment_protection_rule',
payload: testFixtures.deployment_protection_rule,
});

expect(mock.pendingMocks()).toStrictEqual([]);
expect(nock.pendingMocks()).toStrictEqual([]);
});
});

describe('pull_request_review.submitted', () => {
test('processes valid deploy comment', async () => {
const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' })
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/actions/runs')
Expand Down Expand Up @@ -250,8 +234,6 @@ describe('GitHub Deployment App', () => {

test('exits early if no matching workflow runs', async () => {
const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' })
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/actions/runs')
Expand All @@ -268,8 +250,6 @@ describe('GitHub Deployment App', () => {

test('exits early if no pending deployments', async () => {
const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' })
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/actions/runs')
Expand All @@ -288,8 +268,6 @@ describe('GitHub Deployment App', () => {

test('exits early if no deployments can be approved', async () => {
const mock = nock('https://api.github.com')
.get('/app')
.reply(200, { slug: 'test-bot' })
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/actions/runs')
Expand Down

0 comments on commit 4a5ea70

Please sign in to comment.