Skip to content

Commit

Permalink
Merge pull request #334 from github/api-version-headers
Browse files Browse the repository at this point in the history
API Version Headers
  • Loading branch information
GrantBirki authored Dec 10, 2024
2 parents 525c08a + f054a56 commit 8a55624
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 96 deletions.
55 changes: 37 additions & 18 deletions __tests__/functions/actions-status.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import {actionStatus} from '../../src/functions/action-status'
import {truncateCommentBody} from '../../src/functions/truncate-comment-body'
import {API_HEADERS} from '../../src/functions/api-headers'

var context
var octokit
Expand Down Expand Up @@ -55,19 +56,22 @@ test('adds a successful status message for a deployment', async () => {
body: 'Everything worked!',
issue_number: 1,
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
content: 'rocket',
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
owner: 'corp',
reaction_id: 123,
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
})

Expand All @@ -79,19 +83,22 @@ test('adds a successful status message for a deployment (with alt message)', asy
body: 'Everything worked!',
issue_number: 1,
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
content: '+1',
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
owner: 'corp',
reaction_id: 123,
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
})

Expand All @@ -103,19 +110,22 @@ test('adds a failure status message for a deployment', async () => {
body: 'Everything failed!',
issue_number: 1,
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
content: '-1',
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
owner: 'corp',
reaction_id: 123,
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
})

Expand All @@ -125,19 +135,22 @@ test('uses default log url when the "message" variable is empty for failures', a
body: 'Unknown error, [check logs](https://github.com/corp/test/actions/runs/12345) for more details.',
issue_number: 1,
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
content: '-1',
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
owner: 'corp',
reaction_id: 123,
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
})

Expand All @@ -147,19 +160,22 @@ test('uses default log url when the "message" variable is empty for a success',
body: 'Unknown error, [check logs](https://github.com/corp/test/actions/runs/12345) for more details.',
issue_number: 1,
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
content: 'rocket',
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
owner: 'corp',
reaction_id: 123,
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
})

Expand All @@ -172,18 +188,21 @@ test('truncates the message when it is too large for an issue comment', async ()
body: truncateCommentBody(message),
issue_number: 1,
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
content: 'rocket',
owner: 'corp',
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
comment_id: '1',
owner: 'corp',
reaction_id: 123,
repo: 'test'
repo: 'test',
headers: API_HEADERS
})
})
4 changes: 3 additions & 1 deletion __tests__/functions/deployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
activeDeployment
} from '../../src/functions/deployment'
import * as core from '@actions/core'
import {API_HEADERS} from '../../src/functions/api-headers'

var octokit
var context
Expand Down Expand Up @@ -117,7 +118,8 @@ test('creates an in_progress deployment status', async () => {
state: 'in_progress',
environment: environment,
environment_url: null,
log_url: logUrl
log_url: logUrl,
headers: API_HEADERS
})
})

Expand Down
19 changes: 13 additions & 6 deletions __tests__/functions/unlock.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import {unlock} from '../../src/functions/unlock'
import * as actionStatus from '../../src/functions/action-status'
import {API_HEADERS} from '../../src/functions/api-headers'

class NotFoundError extends Error {
constructor(message) {
Expand Down Expand Up @@ -54,7 +55,8 @@ test('successfully releases a deployment lock with the unlock function', async (
expect(octokit.rest.git.deleteRef).toHaveBeenCalledWith({
owner: 'corp',
repo: 'test',
ref: 'heads/production-branch-deploy-lock'
ref: 'heads/production-branch-deploy-lock',
headers: API_HEADERS
})
})

Expand All @@ -63,7 +65,8 @@ test('successfully releases a deployment lock with the unlock function and a pas
expect(octokit.rest.git.deleteRef).toHaveBeenCalledWith({
owner: 'corp',
repo: 'test',
ref: 'heads/staging-branch-deploy-lock'
ref: 'heads/staging-branch-deploy-lock',
headers: API_HEADERS
})
})

Expand All @@ -73,7 +76,8 @@ test('successfully releases a GLOBAL deployment lock with the unlock function',
expect(octokit.rest.git.deleteRef).toHaveBeenCalledWith({
owner: 'corp',
repo: 'test',
ref: 'heads/global-branch-deploy-lock'
ref: 'heads/global-branch-deploy-lock',
headers: API_HEADERS
})
})

Expand All @@ -83,7 +87,8 @@ test('successfully releases a development environment deployment lock with the u
expect(octokit.rest.git.deleteRef).toHaveBeenCalledWith({
owner: 'corp',
repo: 'test',
ref: 'heads/development-branch-deploy-lock'
ref: 'heads/development-branch-deploy-lock',
headers: API_HEADERS
})
})

Expand All @@ -94,7 +99,8 @@ test('successfully releases a development environment deployment lock with the u
expect(octokit.rest.git.deleteRef).toHaveBeenCalledWith({
owner: 'corp',
repo: 'test',
ref: 'heads/development-branch-deploy-lock'
ref: 'heads/development-branch-deploy-lock',
headers: API_HEADERS
})
})

Expand All @@ -105,7 +111,8 @@ test('successfully releases a deployment lock with the unlock function - silent
expect(octokit.rest.git.deleteRef).toHaveBeenCalledWith({
owner: 'corp',
repo: 'test',
ref: 'heads/production-branch-deploy-lock'
ref: 'heads/production-branch-deploy-lock',
headers: API_HEADERS
})
})

Expand Down
Loading

0 comments on commit 8a55624

Please sign in to comment.