Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading