Skip to content

Commit

Permalink
Fix get commit function that was returning an array
Browse files Browse the repository at this point in the history
Change-type: patch
Signed-off-by: Kyle Harding <kyle@balena.io>
  • Loading branch information
klutchell committed Dec 6, 2024
1 parent 937aeb5 commit 3e079d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Commit = components['schemas']['commit'];
// https://docs.github.com/en/rest/commits/commits#get-a-commit
export async function getCommit(context: any, sha: string): Promise<Commit> {
const request = context.repo({
sha,
ref: sha,
});
const { data: commit } = await context.octokit.rest.repos.getCommit(request);
return commit;
Expand Down
30 changes: 10 additions & 20 deletions tests/handlers/deployment-protection-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ describe('Deployment Protection Rule Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 5 }, committer: { id: 123 } })
.post(
'/repos/test-org/test-repo/actions/runs/1234/deployment_protection_rule',
Expand Down Expand Up @@ -114,8 +113,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [])
Expand All @@ -142,8 +140,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [])
Expand All @@ -168,8 +165,7 @@ describe('Deployment Protection Rule Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 5 }, committer: { id: 123 } })
.post(
'/repos/test-org/test-repo/actions/runs/1234/deployment_protection_rule',
Expand All @@ -190,8 +186,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [
Expand Down Expand Up @@ -223,8 +218,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [
Expand Down Expand Up @@ -256,8 +250,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 456 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [
Expand Down Expand Up @@ -291,8 +284,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 456 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [
Expand Down Expand Up @@ -326,8 +318,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [
Expand Down Expand Up @@ -361,8 +352,7 @@ describe('Deployment Protection Rule Handler', () => {
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/app')
.reply(200, { id: 456 })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/pulls/123/reviews')
.reply(200, [])
Expand Down
18 changes: 6 additions & 12 deletions tests/handlers/pull-request-review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ describe('Pull Request Review Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/actions/runs')
.query(true)
Expand Down Expand Up @@ -153,8 +152,7 @@ describe('Pull Request Review Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 456 } });

await probot.receive({
Expand All @@ -180,8 +178,7 @@ describe('Pull Request Review Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 456 }, committer: { id: 123 } });

await probot.receive({
Expand All @@ -196,8 +193,7 @@ describe('Pull Request Review Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/actions/runs')
.query(true)
Expand All @@ -215,8 +211,7 @@ describe('Pull Request Review Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/actions/runs')
.query(true)
Expand All @@ -236,8 +231,7 @@ describe('Pull Request Review Handler', () => {
const mock = nock('https://api.github.com')
.post('/app/installations/12345678/access_tokens')
.reply(200, { token: 'test', permissions: { issues: 'write' } })
.get('/repos/test-org/test-repo/commits')
.query(true)
.get('/repos/test-org/test-repo/commits/test-sha')
.reply(200, { author: { id: 123 }, committer: { id: 123 } })
.get('/repos/test-org/test-repo/actions/runs')
.query(true)
Expand Down

0 comments on commit 3e079d7

Please sign in to comment.