Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
feat(jira): add action tasks (#241)
Browse files Browse the repository at this point in the history
Because

- We need actions to complete the user story

This commit

- Provide a draft json schema of each task

8/12 Update
I have implemented all functions to connect to the real API and found
some tasks are related to some APIs that are not compatible with the
current version of Jira. The remaining tasks are:
- TASK_CREATE_ISSUE
- TASK_UPDATE_ISSUE
- TASK_CREATE_SPRINT
- TASK_UPDATE_SPRINT

--------------
7/31 Update
@chuang8511 Hi, I added three more tasks and moved the schema from v1 to
v0 as #205 is merged. There are 5 new tasks now:
- TASK_CREATE_ISSUE
- TASK_UPDATE_ISSUE
- TASK_CREATE_SPRINT
- TASK_UPDATE_SPRINT
- TASK_RANK_EPIC

--------------
7/25
Note that only the last 3 tasks need to be reviewed, as the others are
under review at #205
- TASK_CREATE_ISSUE
- TASK_UPDATE_ISSUE
- TASK_MOVE_ISSUE_TO_EPIC
  • Loading branch information
YCK1130 authored Aug 23, 2024
1 parent 98c4261 commit e756e31
Show file tree
Hide file tree
Showing 14 changed files with 2,150 additions and 272 deletions.
139 changes: 136 additions & 3 deletions application/jira/v0/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ It can carry out the following tasks:
- [List Sprints](#list-sprints)
- [Get Issue](#get-issue)
- [Get Sprint](#get-sprint)
- [Create Issue](#create-issue)
- [Update Issue](#update-issue)
- [Create Sprint](#create-sprint)
- [Update Sprint](#update-sprint)



Expand Down Expand Up @@ -172,9 +176,138 @@ Get a sprint in Jira
| Self (optional) | `self` | string | The URL of the sprint |
| State (optional) | `state` | string | The state of the sprint, can be: `active`, `closed`, `future` |
| Name (optional) | `name` | string | The name of the sprint |
| Start Date (optional) | `start-date` | string | The start date of the sprint. In the RFC3339 format, e.g. 2018-03-05T00:00:00Z |
| End Date (optional) | `end-date` | string | The end date of the sprint. In the RFC3339 format, e.g. 2018-03-05T00:00:00Z |
| Complete Date (optional) | `complete-date` | string | The complete date of the sprint. In the RFC3339 format, e.g. 2018-03-05T00:00:00Z |
| Start Date (optional) | `start-date` | string | The start date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| End Date (optional) | `end-date` | string | The end date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Complete Date (optional) | `complete-date` | string | The complete date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Origin Board ID (optional) | `origin-board-id` | integer | The ID of the origin board |
| Goal (optional) | `goal` | string | The Goal of the sprint |






### Create Issue

Create an issue in Jira


| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_CREATE_ISSUE` |
| Project Key (required) | `project-key` | string | The key of the project, e.g. `INS` |
| Issue Type (required) | `issue-type` | object | The type of the issue, can be: `Task`, `Epic`, `Subtask`, etc. |
| Summary | `summary` | string | The summary of the issue |
| Description | `description` | string | The description of the issue |



| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| ID | `id` | string | The ID of the issue |
| Key | `key` | string | The key of the issue, e.g. `JRA-1330` |
| Self | `self` | string | The URL of the issue |
| Fields | `fields` | object | The fields of the issue. All navigable and Agile fields are returned |
| Issue Type (optional) | `issue-type` | string | The type of the issue, can be: `Task`, `Epic` |
| Summary (optional) | `summary` | string | The summary of the issue |
| Description (optional) | `description` | string | The description of the issue |
| Status (optional) | `status` | string | The status of the issue, can be: `To Do`, `In Progress`, `Done` |






### Update Issue

Update an issue in Jira


| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_UPDATE_ISSUE` |
| Issue Key (required) | `issue-key` | string | The key of the issue, e.g. `JRA-1330` |
| Notify Users | `notify-users` | boolean | Whether to notify users |
| Update | `update` | object | Update an issue in Jira |



| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| ID | `id` | string | The ID of the issue |
| Key | `key` | string | The key of the issue, e.g. `JRA-1330` |
| Self | `self` | string | The URL of the issue |
| Fields | `fields` | object | The fields of the issue. All navigable and Agile fields are returned |
| Issue Type (optional) | `issue-type` | string | The type of the issue, can be: `Task`, `Epic` |
| Summary (optional) | `summary` | string | The summary of the issue |
| Description (optional) | `description` | string | The description of the issue |
| Status (optional) | `status` | string | The status of the issue, can be: `To Do`, `In Progress`, `Done` |






### Create Sprint

Create a sprint in Jira


| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_CREATE_SPRINT` |
| Board Name (required) | `board-name` | string | The name of the board |
| Name (required) | `name` | string | The name of the sprint |
| Goal (required) | `goal` | string | The goal of the sprint |
| Start Date (required) | `start-date` | string | The start date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| End Date (required) | `end-date` | string | The end date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |



| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| ID | `id` | integer | The ID of the sprint |
| Self | `self` | string | The URL of the sprint |
| State (optional) | `state` | string | The state of the sprint, can be: `active`, `closed`, `future` |
| Name (optional) | `name` | string | The name of the sprint |
| Start Date (optional) | `start-date` | string | The start date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| End Date (optional) | `end-date` | string | The end date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Complete Date (optional) | `complete-date` | string | The complete date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Origin Board ID (optional) | `origin-board-id` | integer | The ID of the origin board |
| Goal (optional) | `goal` | string | The Goal of the sprint |






### Update Sprint

Update a sprint in Jira


| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_UPDATE_SPRINT` |
| Sprint ID (required) | `sprint-id` | integer | The ID of the sprint |
| Name (required) | `name` | string | The name of the sprint |
| Goal | `goal` | string | The goal of the sprint |
| Start Date (required) | `start-date` | string | The start date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| End Date (required) | `end-date` | string | The end date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Current State (required) | `current-state` | string | The current state of the sprint, can be: `future`, `active`, `closed` |
| Enter Next State | `enter-next-state` | boolean | Whether to enter the next state. If `true`, the sprint will enter the next state, i.e., `future` -> `active` -> `closed` |



| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| ID | `id` | integer | The ID of the sprint |
| Self | `self` | string | The URL of the sprint |
| State (optional) | `state` | string | The state of the sprint, can be: `active`, `closed`, `future` |
| Name (optional) | `name` | string | The name of the sprint |
| Start Date (optional) | `start-date` | string | The start date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| End Date (optional) | `end-date` | string | The end date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Complete Date (optional) | `complete-date` | string | The complete date of the sprint, e.g. 2018-03-05 (default 00:00 UTC+0). To adjust your time zone, please provide a more detailed RFC3339 format like `2018-03-05T09:00:00Z0000` |
| Origin Board ID (optional) | `origin-board-id` | integer | The ID of the origin board |
| Goal (optional) | `goal` | string | The Goal of the sprint |

Expand Down
65 changes: 36 additions & 29 deletions application/jira/v0/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,49 @@ func (e errBody) Message() string {
return strings.Join(e.Body.Msg, " ")
}

func turnToStringQueryParams(val any) string {
var stringVal string
switch val := val.(type) {
case string:
stringVal = val
case int:
stringVal = fmt.Sprintf("%d", val)
case bool:
stringVal = fmt.Sprintf("%t", val)
case []string:
stringVal = strings.Join(val, ",")
case []int:
var strVals []string
for _, v := range val {
strVals = append(strVals, fmt.Sprintf("%d", v))
}
stringVal = strings.Join(strVals, ",")
default:
return ""
}
return stringVal
}

func addQueryOptions(req *resty.Request, opt interface{}) error {
v := reflect.ValueOf(opt)
if v.Kind() == reflect.Ptr && v.IsNil() {
return nil
}
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
if v.Kind() == reflect.Map {
for _, key := range v.MapKeys() {
if v.MapIndex(key).IsValid() && v.MapIndex(key).CanInterface() {
val := v.MapIndex(key).Interface()
var stringVal string
switch val := val.(type) {
case string:
stringVal = val
case int:
stringVal = fmt.Sprintf("%d", val)
case bool:
stringVal = fmt.Sprintf("%t", val)
default:
continue
}
if stringVal == fmt.Sprintf("%v", reflect.Zero(reflect.TypeOf(val))) {
continue
}
paramName := key.String()
req.SetQueryParam(paramName, stringVal)
if !v.MapIndex(key).IsValid() || !v.MapIndex(key).CanInterface() {
continue
}
val := v.MapIndex(key).Interface()
stringVal := turnToStringQueryParams(val)
if stringVal == fmt.Sprintf("%v", reflect.Zero(reflect.TypeOf(val))) {
continue
}
paramName := key.String()
req.SetQueryParam(paramName, stringVal)
}
} else if v.Kind() == reflect.Struct {
typeOfS := v.Type()
Expand All @@ -131,17 +148,7 @@ func addQueryOptions(req *resty.Request, opt interface{}) error {
continue
}
val := v.Field(i).Interface()
var stringVal string
switch val := val.(type) {
case string:
stringVal = val
case int:
stringVal = fmt.Sprintf("%d", val)
case bool:
stringVal = fmt.Sprintf("%t", val)
default:
continue
}
stringVal := turnToStringQueryParams(val)
if stringVal == fmt.Sprintf("%v", reflect.Zero(reflect.TypeOf(val))) {
continue
}
Expand Down
Loading

0 comments on commit e756e31

Please sign in to comment.