[Admin] Offer Keyset / Seek Pagination #25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Add Issues to Project | |
on: | |
issues: | |
types: | |
- opened | |
jobs: | |
add-to-project: | |
name: Add issue to project | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }} | |
script: | | |
const issue = context.payload.issue; | |
// Get project ID | |
const projectOwner = 'drf-forms'; | |
const projectNumber = 1; | |
// Query for the project ID | |
const projectQuery = ` | |
query($owner: String!, $number: Int!) { | |
user(login: $owner) { | |
projectV2(number: $number) { | |
id | |
fields(first: 20) { | |
nodes { | |
... on ProjectV2SingleSelectField { | |
id | |
name | |
options { | |
id | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
`; | |
const projectData = await github.graphql(projectQuery, { | |
owner: projectOwner, | |
number: projectNumber | |
}); | |
const projectId = projectData.user.projectV2.id; | |
// Find status field ID and the "Idea" option ID | |
let statusFieldId; | |
let ideaOptionId; | |
const fields = projectData.user.projectV2.fields.nodes; | |
for (const field of fields) { | |
if (field.name === 'Status') { | |
statusFieldId = field.id; | |
for (const option of field.options) { | |
if (option.name === 'Idea') { | |
ideaOptionId = option.id; | |
break; | |
} | |
} | |
break; | |
} | |
} | |
// Add issue to project | |
const addToProjectMutation = ` | |
mutation($projectId: ID!, $contentId: ID!) { | |
addProjectV2ItemById(input: { | |
projectId: $projectId | |
contentId: $contentId | |
}) { | |
item { | |
id | |
} | |
} | |
} | |
`; | |
const addResult = await github.graphql(addToProjectMutation, { | |
projectId: projectId, | |
contentId: issue.node_id | |
}); | |
// If status field and Idea option were found, set the status | |
if (statusFieldId && ideaOptionId) { | |
const itemId = addResult.addProjectV2ItemById.item.id; | |
const updateFieldMutation = ` | |
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) { | |
updateProjectV2ItemFieldValue(input: { | |
projectId: $projectId | |
itemId: $itemId | |
fieldId: $fieldId | |
value: { | |
singleSelectOptionId: $optionId | |
} | |
}) { | |
projectV2Item { | |
id | |
} | |
} | |
} | |
`; | |
await github.graphql(updateFieldMutation, { | |
projectId: projectId, | |
itemId: itemId, | |
fieldId: statusFieldId, | |
optionId: ideaOptionId | |
}); | |
} |