Skip to content

Commit e583b76

Browse files
committed
sprinkle in some debug statements
1 parent a6d2b24 commit e583b76

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

__tests__/functions/deployment.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import {
33
latestActiveDeployment,
44
activeDeployment
55
} from '../../src/functions/deployment'
6+
import * as core from '@actions/core'
67

78
var octokit
89
var context
910
var mockDeploymentData
1011
var mockDeploymentResults
1112
beforeEach(() => {
1213
jest.clearAllMocks()
14+
jest.spyOn(core, 'debug').mockImplementation(() => {})
1315
process.env.GITHUB_SERVER_URL = 'https://github.com'
1416

1517
context = {

dist/index.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/deployment.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as core from '@actions/core'
2+
13
// Helper function to add deployment statuses to a PR / ref
24
// :param octokit: The octokit client
35
// :param context: The GitHub Actions event context
@@ -86,18 +88,23 @@ export async function latestActiveDeployment(octokit, context, environment) {
8688
environment: environment
8789
}
8890

91+
let queryNumber = 1
8992
let data = await octokit.graphql(buildQuery(), variables)
9093
// nodes may be empty if no matching deployments were found - ex: []
9194
let nodes = data.repository.deployments.nodes
9295

9396
// If no deployments were found, return null
9497
if (nodes.length === 0) {
98+
core.debug(`no deployments found for ${environment}`)
9599
return null
96100
}
97101

98102
// Check for an active deployment in the first page of deployments
99103
let activeDeployment = nodes.find(deployment => deployment.state === 'ACTIVE')
100104
if (activeDeployment) {
105+
core.debug(
106+
`found active deployment for ${environment} in page ${queryNumber}`
107+
)
101108
return activeDeployment
102109
}
103110

@@ -106,19 +113,31 @@ export async function latestActiveDeployment(octokit, context, environment) {
106113
let endCursor = data.repository.deployments.pageInfo.endCursor
107114

108115
while (hasNextPage) {
116+
queryNumber++
109117
data = await octokit.graphql(buildQuery(endCursor), variables)
110118

111119
nodes = data.repository.deployments.nodes
112120
activeDeployment = nodes.find(deployment => deployment.state === 'ACTIVE')
113121

114122
if (activeDeployment) {
123+
core.debug(
124+
`found active deployment for ${environment} in page ${queryNumber}`
125+
)
115126
return activeDeployment
127+
} else {
128+
core.debug(
129+
`no active deployment found for ${environment} in page ${queryNumber}`
130+
)
116131
}
117132

118133
hasNextPage = data.repository.deployments.pageInfo.hasNextPage
119134
endCursor = data.repository.deployments.pageInfo.endCursor
120135
}
121136

137+
core.debug(
138+
`no active deployment found for ${environment} after ${queryNumber} pages`
139+
)
140+
122141
// If no active deployment was found, return null
123142
return null
124143
}

0 commit comments

Comments
 (0)