Skip to content

Commit 6e78137

Browse files
feature: implemented @current and @next iteration selection (#45)
* feature: implemented @current and @next iteration selection To use this functionality, simply pass @current or @next as the iteration value. * tests: added @current and @next to the test cases * docs: added instructions how to use the @current and @next iteration
1 parent 5f5211c commit 6e78137

File tree

5 files changed

+98
-11
lines changed

5 files changed

+98
-11
lines changed

README.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
To leverage the App authentication with this action the following steps are needed:
152152
153153
- Create a GitHub App under your user or organisation as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app), note the App ID
154-
- Set the needed GitHub App permissions in order for the newly create App to access and manage Org Project, as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/managing-github-apps/editing-a-github-apps-permissions). The minimum required permissions are:
154+
- Set the needed GitHub App permissions in order for the newly create App to access and manage Org Project, as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/managing-github-apps/editing-a-github-apps-permissions). The minimum required permissions are:
155155
- Repo: Actions: RW
156156
- Repo: Checks: RO
157157
- Repo: Contents: RO
@@ -164,10 +164,9 @@ To leverage the App authentication with this action the following steps are need
164164
- Create a private key to authenticate the newly created GitHub App as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps), treat the downloaded key as sensitive material, store it in a GitHub secret accessible by this action.
165165
- Install the app in the target organisation, note the installation ID
166166
- Configure this action with
167-
- `gh_app_secret_key` containing the aforementioned private key
168-
- `gh_app_ID` containing the app ID, auto-generated by GitHub in the first step
169-
- `gh_app_installation_ID` containing the installation ID, auto-generated by GitHub in the previous step. Binging the App to the Org
170-
167+
- `gh_app_secret_key` containing the aforementioned private key
168+
- `gh_app_ID` containing the app ID, auto-generated by GitHub in the first step
169+
- `gh_app_installation_ID` containing the installation ID, auto-generated by GitHub in the previous step. Binging the App to the Org
171170

172171
## JSON-Definition
173172

@@ -307,6 +306,25 @@ jobs:
307306
custom_field_values: ${{ env.custom_field_values }}
308307
```
309308

309+
Since version 1.3.0 the iteration field also supports the following values:
310+
311+
- @current: the current iteration
312+
- @next: the next iteration
313+
314+
Both of these values are provided by the `project-beta-automations` package. The following json provides an example of how to use these values:
315+
316+
Next iteration:
317+
318+
```yaml
319+
'[{\"name\": \"Iteration\",\"type\": \"iteration\",\"value\": \"@next\"}]'
320+
```
321+
322+
Current iteration:
323+
324+
```yaml
325+
'[{\"name\": \"Iteration\",\"type\": \"iteration\",\"value\": \"@current\"}]'
326+
```
327+
310328
## Detailed example
311329

312330
Since this repository is also covered by this automation, you can take a look at the definition within the [project-automation.yml](.github/workflows/project_automations.yml) file to check how it is defined here.

gh_api_lib_organization.sh

+17-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,24 @@ function extractOrganizationFieldID() {
4040
# extractOrganizationFieldNodeIterationSettingValue returns the field node setting value id
4141
# 1: field name
4242
# 2: select value
43+
#
44+
# NOTE: If the value is @current or @next, we check the the array of iterations and return the current or next iteration id.
4345
function extractOrganizationFieldNodeIterationSettingValue() {
44-
local fieldName=$(echo $1 | sed -e "s+\"++g") # remove quotes
45-
selectValue=$(echo $2 | sed -e "s+\"++g") # remove quotes
46-
jq ".data.organization.projectNext.fields.nodes[] | select(.name == \"$fieldName\").settings | fromjson.configuration.iterations[] | select(.title==\"$selectValue\") |.id" $TMP_STORE_LOCATION | sed -e "s+\"++g"
46+
local field_name=$(echo $1 | sed -e "s+\"++g") # remove quotes
47+
select_value=$(echo $2 | sed -e "s+\"++g") # remove quotes
48+
49+
iterations_for_field=$(jq ".data.organization.projectNext.fields.nodes[] | select(.name==\"$field_name\").settings | fromjson.configuration.iterations[]" $TMP_STORE_LOCATION)
50+
dates=$(echo $iterations_for_field | jq -r ".start_date" | sort )
51+
STRINGTEST=(${dates[@]})
52+
if [ "$select_value" == "@current" ]; then
53+
iteration_selected=${STRINGTEST[0]}
54+
echo -e $iterations_for_field | jq "select(.start_date==\"$iteration_selected\") |.id" | sed -e "s+\"++g"
55+
elif [ "$select_value" == "@next" ]; then
56+
iteration_selected=${STRINGTEST[1]}
57+
echo -e $iterations_for_field | jq "select(.start_date==\"$iteration_selected\") |.id" | sed -e "s+\"++g"
58+
else
59+
echo -e $iterations_for_field | jq "select(.title==\"$select_value\") |.id" | sed -e "s+\"++g"
60+
fi
4761
}
4862

4963
# extractOrganizationFieldNodeSelectSettingValue returns the field node setting value id

gh_api_lib_user.sh

+17-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,24 @@ function extractUserFieldID() {
4040
# extractUserFieldNodeIterationSettingValue returns the field node setting value id
4141
# 1: field name
4242
# 2: select value
43+
#
44+
# NOTE: If the value is @current or @next, we check the the array of iterations and return the current or next iteration id.
4345
function extractUserFieldNodeIterationSettingValue() {
44-
local fieldName=$(echo $1 | sed -e "s+\"++g") # remove quotes
45-
selectValue=$(echo $2 | sed -e "s+\"++g") # remove quotes
46-
jq ".data.user.projectNext.fields.nodes[] | select(.name == \"$fieldName\").settings | fromjson.configuration.iterations[] | select(.title==\"$selectValue\") |.id" $TMP_STORE_LOCATION | sed -e "s+\"++g"
46+
local field_name=$(echo $1 | sed -e "s+\"++g") # remove quotes
47+
select_value=$(echo $2 | sed -e "s+\"++g") # remove quotes
48+
49+
iterations_for_field=$(jq ".data.user.projectNext.fields.nodes[] | select(.name==\"$field_name\").settings | fromjson.configuration.iterations[]" $TMP_STORE_LOCATION)
50+
dates=$(echo $iterations_for_field | jq -r ".start_date" | sort )
51+
STRINGTEST=(${dates[@]})
52+
if [ "$select_value" == "@current" ]; then
53+
iteration_selected=${STRINGTEST[0]}
54+
echo -e $iterations_for_field | jq "select(.start_date==\"$iteration_selected\") |.id" | sed -e "s+\"++g"
55+
elif [ "$select_value" == "@next" ]; then
56+
iteration_selected=${STRINGTEST[1]}
57+
echo -e $iterations_for_field | jq "select(.start_date==\"$iteration_selected\") |.id" | sed -e "s+\"++g"
58+
else
59+
echo -e $iterations_for_field | jq "select(.title==\"$select_value\") |.id" | sed -e "s+\"++g"
60+
fi
4761
}
4862

4963
# extractUserFieldNodeSelectSettingValue returns the field node setting value id

test_organization.sh

+20
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,23 @@ custom_fields="[
5353
ENTRYPOINT_TYPE=custom_field
5454
RESOURCE_NODE_VALUE=$custom_fields
5555
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"
56+
57+
custom_fields="[
58+
{
59+
\"name\": \"Iteration\",
60+
\"type\": \"iteration\",
61+
\"value\": \"@next\"
62+
}
63+
]"
64+
RESOURCE_NODE_VALUE=$custom_fields
65+
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"
66+
67+
custom_fields="[
68+
{
69+
\"name\": \"Iteration\",
70+
\"type\": \"iteration\",
71+
\"value\": \"@current\"
72+
}
73+
]"
74+
RESOURCE_NODE_VALUE=$custom_fields
75+
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"

test_user.sh

+21
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,24 @@ custom_fields="[
5252
ENTRYPOINT_TYPE=custom_field
5353
RESOURCE_NODE_VALUE=$custom_fields
5454
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"
55+
56+
57+
custom_fields="[
58+
{
59+
\"name\": \"Iteration\",
60+
\"type\": \"iteration\",
61+
\"value\": \"@next\"
62+
}
63+
]"
64+
RESOURCE_NODE_VALUE=$custom_fields
65+
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"
66+
67+
custom_fields="[
68+
{
69+
\"name\": \"Iteration\",
70+
\"type\": \"iteration\",
71+
\"value\": \"@current\"
72+
}
73+
]"
74+
RESOURCE_NODE_VALUE=$custom_fields
75+
$ENTRYPOINT_SCRIPT "$ENTRYPOINT_MODE" "$ENTRYPOINT_TYPE" "$ORG_OR_USER_NAME" "$PROJECT_ID" "$RESOURCE_NODE_ID" "$RESOURCE_NODE_VALUE"

0 commit comments

Comments
 (0)