Port PR from PBC-Java: Github: CodeQl action #34
This file contains 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: Issue tracking | |
on: | |
issues: | |
types: | |
- opened | |
jobs: | |
track_issue: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate token | |
id: generate_token | |
uses: tibdex/[email protected] | |
with: | |
app_id: ${{ secrets.PBS_PROJECT_APP_ID }} | |
private_key: ${{ secrets.PBS_PROJECT_APP_PEM }} | |
- name: Get project data | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
ORGANIZATION: prebid | |
DATE_FIELD: Created on | |
PROJECT_NUMBER: 4 | |
run: | | |
gh api graphql -f query=' | |
query($org: String!, $number: Int!) { | |
organization(login: $org){ | |
projectV2(number: $number) { | |
id | |
fields(first:100) { | |
nodes { | |
... on ProjectV2Field { | |
id | |
name | |
} | |
... on ProjectV2SingleSelectField { | |
id | |
name | |
options { | |
id | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json | |
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV | |
echo 'DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "'"$DATE_FIELD"'") | .id' project_data.json) >> $GITHUB_ENV | |
- name: Add issue to project | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
ISSUE_ID: ${{ github.event.issue.node_id }} | |
run: | | |
gh api graphql -f query=' | |
mutation($project:ID!, $issue:ID!) { | |
addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) { | |
item { | |
id, | |
content { | |
... on Issue { | |
createdAt | |
} | |
... on PullRequest { | |
createdAt | |
} | |
} | |
} | |
} | |
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID > issue_data.json | |
echo 'ITEM_ID='$(jq '.data.addProjectV2ItemById.item.id' issue_data.json) >> $GITHUB_ENV | |
echo 'ITEM_CREATION_DATE='$(jq '.data.addProjectV2ItemById.item.content.createdAt' issue_data.json | cut -c 2-11) >> $GITHUB_ENV | |
- name: Set fields | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
gh api graphql -f query=' | |
mutation ( | |
$project: ID! | |
$item: ID! | |
$date_field: ID! | |
$date_value: Date! | |
) { | |
set_creation_date: updateProjectV2ItemFieldValue(input: { | |
projectId: $project | |
itemId: $item | |
fieldId: $date_field | |
value: { | |
date: $date_value | |
} | |
}) { | |
projectV2Item { | |
id | |
} | |
} | |
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$DATE_FIELD_ID -f date_value=$ITEM_CREATION_DATE --silent |