Skip to content

Commit 066cd4f

Browse files
authored
fix: update fetchOpenPullRequests method to pass organisation in github action workflow for prioritization (#33073)
### Issue # (if applicable) N/A ### Reason for this change `PR Prioritization R5 Check` and` PR Prioritization R2 Check` github action workflow is failing since it is not able to call the graphql api with the repo owner. ``` GraphqlResponseError: Request failed due to following response errors: - Variable $owner of type String! was provided invalid value at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:6669:[13](https://github.com/aws/aws-cdk/actions/runs/12902208172/job/36014470718#step:3:14) Error: Unhandled error: GraphqlResponseError: Request failed due to following response errors: - Variable $owner of type String! was provided invalid value ``` ### Description of changes R2 and R5 prioritization uses `fetchOpenPullRequests` method that needs to be updated with organisation parameter and query as the `aws-cdk` repo is under `aws` org. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Ran unit test and tested in local repo. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d6e3c61 commit 066cd4f

File tree

4 files changed

+82
-77
lines changed

4 files changed

+82
-77
lines changed

scripts/@aws-cdk/script-tests/prioritization/helpers/mock-data.js

+39-35
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,22 @@ exports.createMockGithubForR5 = ({
113113
graphql
114114
// First call - fetch open PRs
115115
.mockResolvedValueOnce({
116-
repository: {
117-
pullRequests: {
118-
nodes: [{
119-
id: 'PR_123',
120-
number: 123,
121-
draft,
122-
updatedAt,
123-
labels: {
124-
nodes: labels.map(label => ({ name: label }))
116+
organization: {
117+
repository: {
118+
pullRequests: {
119+
nodes: [{
120+
id: 'PR_123',
121+
number: 123,
122+
draft,
123+
updatedAt,
124+
labels: {
125+
nodes: labels.map(label => ({ name: label }))
126+
}
127+
}],
128+
pageInfo: {
129+
hasNextPage: false,
130+
endCursor: null
125131
}
126-
}],
127-
pageInfo: {
128-
hasNextPage: false,
129-
endCursor: null
130132
}
131133
}
132134
}
@@ -177,33 +179,35 @@ exports.createMockGithubForR2 = ({
177179
graphql
178180
// First call - fetch open PRs
179181
.mockResolvedValueOnce({
182+
organization: {
180183
repository: {
181-
pullRequests: {
184+
pullRequests: {
185+
nodes: [{
186+
id: 'PR_123',
187+
number: 123,
188+
reviews: {
189+
nodes: approved ? [
190+
{ state: 'APPROVED' }
191+
] : []
192+
},
193+
commits: {
182194
nodes: [{
183-
id: 'PR_123',
184-
number: 123,
185-
reviews: {
186-
nodes: approved ? [
187-
{ state: 'APPROVED' }
188-
] : []
189-
},
190-
commits: {
191-
nodes: [{
192-
commit: {
193-
statusCheckRollup: {
194-
state: checksState
195-
}
196-
}
197-
}]
195+
commit: {
196+
statusCheckRollup: {
197+
state: checksState
198198
}
199-
}],
200-
pageInfo: {
201-
hasNextPage: false,
202-
endCursor: null
203-
}
199+
}
200+
}]
201+
}
202+
}],
203+
pageInfo: {
204+
hasNextPage: false,
205+
endCursor: null
204206
}
207+
}
205208
}
206-
})
209+
}
210+
})
207211
// Second call - fetch project fields
208212
.mockResolvedValueOnce(projectFields)
209213
// Third call - check if PR is in project

scripts/prioritization/assign-r2-priority.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ module.exports = async ({ github }) => {
2525
while (hasNextPage) {
2626
const result = await fetchOpenPullRequests({
2727
github,
28-
owner: PROJECT_CONFIG.owner,
28+
org: PROJECT_CONFIG.org,
2929
repo: PROJECT_CONFIG.repo,
3030
cursor: cursor,
3131
});
3232

33-
const pullRequests = result.repository.pullRequests;
33+
const pullRequests = result.organization.repository.pullRequests;
3434
allPRs = allPRs.concat(pullRequests.nodes);
3535

3636
// Update pagination info

scripts/prioritization/assign-r5-priority.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ module.exports = async ({ github }) => {
2727
while (hasNextPage) {
2828
const result = await fetchOpenPullRequests({
2929
github,
30-
owner: PROJECT_CONFIG.owner,
30+
org: PROJECT_CONFIG.org,
3131
repo: PROJECT_CONFIG.repo,
3232
cursor: cursor,
3333
});
3434

35-
const pullRequests = result.repository.pullRequests;
35+
const pullRequests = result.organization.repository.pullRequests;
3636
allPRs = allPRs.concat(pullRequests.nodes);
3737

3838
// Update pagination info

scripts/prioritization/project-api.js

+39-38
Original file line numberDiff line numberDiff line change
@@ -99,55 +99,56 @@ const updateProjectField = async ({
9999
};
100100

101101

102-
/**
103-
* Fetches open pull requests from a repository with pagination support.
104-
* Includes data needed for both R2 and R5 priority processing.
105-
* @param {Object} params - The parameters for fetching pull requests
106-
* @param {Object} params.github - The GitHub API client
107-
* @param {string} params.owner - The repository owner
108-
* @param {string} params.repo - The repository name
109-
* @param {string} [params.cursor] - The pagination cursor
110-
* @returns {Promise<Object>} The GraphQL mutation response
111-
*/
112-
const fetchOpenPullRequests = async ({ github, owner, repo, cursor }) => {
102+
/**
103+
* Fetches open pull requests from a repository with pagination support.
104+
* Includes data needed for both R2 and R5 priority processing.
105+
* @param {Object} params - The parameters for fetching pull requests
106+
* @param {Object} params.github - The GitHub API client
107+
* @param {string} params.org - The organization name
108+
* @param {string} params.repo - The repository name
109+
* @param {string} [params.cursor] - The pagination cursor
110+
* @returns {Promise<Object>} The GraphQL mutation response
111+
*/
112+
const fetchOpenPullRequests = async ({ github, org, repo, cursor }) => {
113113
return github.graphql(
114114
`
115-
query($owner: String!, $repo: String!, $cursor: String) {
116-
repository(owner: $owner, name: $repo) {
117-
pullRequests(first: 100, after: $cursor, states: OPEN) {
118-
nodes {
119-
id
120-
number
121-
updatedAt
122-
reviews(last: 100) {
123-
nodes {
124-
state
115+
query($org: String!, $repo: String!, $cursor: String) {
116+
organization(login: $org) {
117+
repository(name: $repo) {
118+
pullRequests(first: 100, after: $cursor, states: OPEN) {
119+
nodes {
120+
id
121+
number
122+
updatedAt
123+
reviews(last: 100) {
124+
nodes {
125+
state
126+
}
125127
}
126-
}
127-
commits(last: 1) {
128-
nodes {
129-
commit {
130-
statusCheckRollup {
131-
state
128+
commits(last: 1) {
129+
nodes {
130+
commit {
131+
statusCheckRollup {
132+
state
133+
}
132134
}
133135
}
134136
}
135-
}
136-
labels(first: 10) {
137-
nodes {
138-
name
137+
labels(first: 10) {
138+
nodes {
139+
name
140+
}
139141
}
140142
}
141-
}
142-
pageInfo {
143-
hasNextPage
144-
endCursor
143+
pageInfo {
144+
hasNextPage
145+
endCursor
146+
}
145147
}
146148
}
147149
}
148-
}
149-
`,
150-
{ owner, repo, cursor }
150+
}`,
151+
{ org, repo, cursor }
151152
);
152153
};
153154

0 commit comments

Comments
 (0)