-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #1944] Script to create issues from CLI #1952
Open
widal001
wants to merge
1
commit into
main
Choose a base branch
from
issue-1944-create-issue-cli-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+181
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
query ( | ||
$org: String! | ||
$project: Int! | ||
$fieldName: String! | ||
$fieldValue: [String!] | ||
) { | ||
login: organization(login: $org) { | ||
projectV2(number: $project) { | ||
projectId: id | ||
field(name: $fieldName) { | ||
... on ProjectV2SingleSelectField { | ||
fieldId: id | ||
options(names: $fieldValue) { | ||
optionId: id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#! /bin/bash | ||
# Create a new issue and update GitHub project values | ||
# Usage: | ||
# ./scripts/create-issue.sh \ | ||
# --org HHS | ||
# --repo simpler-grants-gov | ||
# --project 13 | ||
# --title "New issue title" | ||
# --body "Body of the issue" | ||
# --milestone "<name of milestone>" | ||
# --deliverable "<name of deliverable (case sensitive)>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we are deprecating this as well. |
||
# --track "<name of track (case sensitive)>" | ||
|
||
# ################################################## | ||
# parse command line args with format `--option arg` | ||
# ################################################## | ||
# see this stack overflow for more details: | ||
# https://stackoverflow.com/a/14203146/7338319 | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
--org) | ||
org="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--repo) | ||
repo="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--project) | ||
project="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--title) | ||
title="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--body) | ||
body="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--labels) | ||
labels="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--milestone) | ||
milestone="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--deliverable) | ||
deliverable="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--track) | ||
track="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--status) | ||
status="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-*|--*) | ||
echo "Unknown option $1" | ||
exit 1 | ||
;; | ||
*) | ||
positional_args+=("$1") # save positional arg | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
|
||
# ######################################## | ||
# create the issue | ||
# ######################################## | ||
echo "Creating the issue" | ||
issue_url=$(gh issue create \ | ||
--title "${title}" \ | ||
--body "${body}" \ | ||
--label "${labels}" \ | ||
--milestone "${milestone}" \ | ||
--repo "${org}/${repo}") | ||
echo "Successfully created issue: ${issue_url}" | ||
|
||
# ####################################### | ||
# add issue to the project and get its id | ||
# ####################################### | ||
echo "Adding issue: ${issue_url} to project: ${org}/${project}" | ||
item_id=$(gh project item-add $project \ | ||
--url "${issue_url}" \ | ||
--owner "${org}" \ | ||
--format json \ | ||
--jq '.id') | ||
echo "Successfully create project item with id: ${item_id}" | ||
|
||
# ####################################### | ||
# create a function to update project field | ||
# ####################################### | ||
function updateProjectField() | ||
{ | ||
query=$(cat ./queries/get-single-select-field.graphql) | ||
field_name=$1 | ||
field_value=$2 | ||
# get the id for the field and the value we want to set | ||
field_data=$(gh api graphql \ | ||
--paginate \ | ||
--field org="${org}" \ | ||
--field project="${project}" \ | ||
--field fieldName="${field_name}" \ | ||
--field fieldValue="${field_value}" \ | ||
-f query="${query}" \ | ||
--jq "{ | ||
project: .data.login.projectV2.projectId, | ||
field: .data.login.projectV2.field.fieldId, | ||
value: .data.login.projectV2.field.options[0].optionId, | ||
}") | ||
echo "Got field IDs: ${field_data}" | ||
# parse each id into its own variable for the update command | ||
# use --raw-output to exclude surrounding quotes which break item-edit CLI command | ||
project_id=$(echo $field_data | jq --raw-output '.project') | ||
field_id=$(echo $field_data | jq --raw-output '.field') | ||
value_id=$(echo $field_data | jq --raw-output '.value') | ||
# update the value of this field | ||
gh project item-edit \ | ||
--id $item_id \ | ||
--project-id $project_id \ | ||
--field-id $field_id \ | ||
--single-select-option-id $value_id | ||
} | ||
|
||
# ####################################### | ||
# Use that function to update fields | ||
# ####################################### | ||
if [[ -z "${deliverable}" ]]; | ||
then echo "Value for deliverable not passed, using default"; | ||
else | ||
echo "Setting the value of the deliverable column" | ||
updateProjectField "Deliverable" "${deliverable}"; | ||
fi | ||
if [[ -z "${track}" ]]; | ||
then echo "Value for track not passed, using default"; | ||
else | ||
echo "Setting the value of the track column" | ||
updateProjectField "Track" "${track}"; | ||
fi | ||
if [[ -z "${status}" ]]; | ||
then echo "Value for status not passed, using default"; | ||
else | ||
echo "Setting the value of the status column" | ||
updateProjectField "Status" "${status}"; | ||
fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that we aren't using milestones anymore.