Skip to content

Commit

Permalink
fix: update fetchOpenPullRequests method to pass organisation in gith…
Browse files Browse the repository at this point in the history
…ub 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*
  • Loading branch information
godwingrs22 authored Jan 22, 2025
1 parent d6e3c61 commit 066cd4f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 77 deletions.
74 changes: 39 additions & 35 deletions scripts/@aws-cdk/script-tests/prioritization/helpers/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,22 @@ exports.createMockGithubForR5 = ({
graphql
// First call - fetch open PRs
.mockResolvedValueOnce({
repository: {
pullRequests: {
nodes: [{
id: 'PR_123',
number: 123,
draft,
updatedAt,
labels: {
nodes: labels.map(label => ({ name: label }))
organization: {
repository: {
pullRequests: {
nodes: [{
id: 'PR_123',
number: 123,
draft,
updatedAt,
labels: {
nodes: labels.map(label => ({ name: label }))
}
}],
pageInfo: {
hasNextPage: false,
endCursor: null
}
}],
pageInfo: {
hasNextPage: false,
endCursor: null
}
}
}
Expand Down Expand Up @@ -177,33 +179,35 @@ exports.createMockGithubForR2 = ({
graphql
// First call - fetch open PRs
.mockResolvedValueOnce({
organization: {
repository: {
pullRequests: {
pullRequests: {
nodes: [{
id: 'PR_123',
number: 123,
reviews: {
nodes: approved ? [
{ state: 'APPROVED' }
] : []
},
commits: {
nodes: [{
id: 'PR_123',
number: 123,
reviews: {
nodes: approved ? [
{ state: 'APPROVED' }
] : []
},
commits: {
nodes: [{
commit: {
statusCheckRollup: {
state: checksState
}
}
}]
commit: {
statusCheckRollup: {
state: checksState
}
}],
pageInfo: {
hasNextPage: false,
endCursor: null
}
}
}]
}
}],
pageInfo: {
hasNextPage: false,
endCursor: null
}
}
}
})
}
})
// Second call - fetch project fields
.mockResolvedValueOnce(projectFields)
// Third call - check if PR is in project
Expand Down
4 changes: 2 additions & 2 deletions scripts/prioritization/assign-r2-priority.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ module.exports = async ({ github }) => {
while (hasNextPage) {
const result = await fetchOpenPullRequests({
github,
owner: PROJECT_CONFIG.owner,
org: PROJECT_CONFIG.org,
repo: PROJECT_CONFIG.repo,
cursor: cursor,
});

const pullRequests = result.repository.pullRequests;
const pullRequests = result.organization.repository.pullRequests;
allPRs = allPRs.concat(pullRequests.nodes);

// Update pagination info
Expand Down
4 changes: 2 additions & 2 deletions scripts/prioritization/assign-r5-priority.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ module.exports = async ({ github }) => {
while (hasNextPage) {
const result = await fetchOpenPullRequests({
github,
owner: PROJECT_CONFIG.owner,
org: PROJECT_CONFIG.org,
repo: PROJECT_CONFIG.repo,
cursor: cursor,
});

const pullRequests = result.repository.pullRequests;
const pullRequests = result.organization.repository.pullRequests;
allPRs = allPRs.concat(pullRequests.nodes);

// Update pagination info
Expand Down
77 changes: 39 additions & 38 deletions scripts/prioritization/project-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,55 +99,56 @@ const updateProjectField = async ({
};


/**
* Fetches open pull requests from a repository with pagination support.
* Includes data needed for both R2 and R5 priority processing.
* @param {Object} params - The parameters for fetching pull requests
* @param {Object} params.github - The GitHub API client
* @param {string} params.owner - The repository owner
* @param {string} params.repo - The repository name
* @param {string} [params.cursor] - The pagination cursor
* @returns {Promise<Object>} The GraphQL mutation response
*/
const fetchOpenPullRequests = async ({ github, owner, repo, cursor }) => {
/**
* Fetches open pull requests from a repository with pagination support.
* Includes data needed for both R2 and R5 priority processing.
* @param {Object} params - The parameters for fetching pull requests
* @param {Object} params.github - The GitHub API client
* @param {string} params.org - The organization name
* @param {string} params.repo - The repository name
* @param {string} [params.cursor] - The pagination cursor
* @returns {Promise<Object>} The GraphQL mutation response
*/
const fetchOpenPullRequests = async ({ github, org, repo, cursor }) => {
return github.graphql(
`
query($owner: String!, $repo: String!, $cursor: String) {
repository(owner: $owner, name: $repo) {
pullRequests(first: 100, after: $cursor, states: OPEN) {
nodes {
id
number
updatedAt
reviews(last: 100) {
nodes {
state
query($org: String!, $repo: String!, $cursor: String) {
organization(login: $org) {
repository(name: $repo) {
pullRequests(first: 100, after: $cursor, states: OPEN) {
nodes {
id
number
updatedAt
reviews(last: 100) {
nodes {
state
}
}
}
commits(last: 1) {
nodes {
commit {
statusCheckRollup {
state
commits(last: 1) {
nodes {
commit {
statusCheckRollup {
state
}
}
}
}
}
labels(first: 10) {
nodes {
name
labels(first: 10) {
nodes {
name
}
}
}
}
pageInfo {
hasNextPage
endCursor
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
`,
{ owner, repo, cursor }
}`,
{ org, repo, cursor }
);
};

Expand Down

0 comments on commit 066cd4f

Please sign in to comment.