Skip to content
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

Support clearing fields #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -248,7 +248,7 @@ A single json object is defined as follows:
{
"name": "Sample Text Field", # defines the name of the custom field
"type": "text", # can be one of: text, number, date, single_select, iteration
"value": "High" # defines the value to set (string)
"value": "High" # defines the value to set (string), use null to clear the field
}
```

Expand Down
8 changes: 7 additions & 1 deletion entrypoint.sh
Expand Up @@ -122,9 +122,15 @@ function updateFieldScope() {
nameField=$(echo $RESOURCE_NODE_VALUE | jq ".[$x].name")
typeField=$(echo $RESOURCE_NODE_VALUE | jq ".[$x].type" | sed 's/\"//g')
valueField=$(echo $RESOURCE_NODE_VALUE | jq ".[$x].value")
if [ "$nameField" == "null" ] || [ "$valueField" == "null" ]; then
if [ "$nameField" == "null" ]; then
# no more custom fields
break
elif [ "$valueField" == "null" ]; then
local fieldID=$(extractFieldID "$nameField")
log="$log\n\n$nameField: $fieldID"
log="$log\Clearing field: $nameField"
response=$(clearField "$PROJECT_UUID" "$PROJECT_ITEM_UUID" $fieldID)
log="$log\n$response\n"
else
local fieldID=$(extractFieldID "$nameField")
log="$log\n\n$nameField: $fieldID"
Expand Down
29 changes: 29 additions & 0 deletions gh_api_global.sh
Expand Up @@ -234,6 +234,35 @@ function updateDateField() {
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f fieldid=$FIELD_ID -f fieldValue="$FIELD_VALUE" | sed -e "s+\"++g"
}

# clearField clears the given item field
# Required arguments:
# 1: project id
# 2: project item id
# 3: field id
function clearField() {
local PROJECT_ID=$1
local ITEM_ID=$2
local FIELD_ID=$3
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$fieldid: ID!
) {
clearProjectV2ItemFieldValue(
input: {
projectId: $project
itemId: $item
fieldId: $fieldid
}
) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f fieldid=$FIELD_ID -f | sed -e "s+\"++g"
}

# getPullRequestByNodeID returns the pull request data by node id
# $1: node id
function getPullRequestByNodeID() {
Expand Down
12 changes: 12 additions & 0 deletions test_user.sh
Expand Up @@ -88,4 +88,16 @@ custom_fields="[
}
]"
RESOURCE_NODE_VALUE=$custom_fields
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"

echo "===== clear custom fields"

custom_fields="[
{
\"name\": \"Date\",
\"type\": \"date\",
\"value\": \"null\"
}
]"
RESOURCE_NODE_VALUE=$custom_fields
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"