@@ -35,6 +35,14 @@ const updateIssue = async (issueId, fields) => {
3535 if ( response . status !== 204 ) throw new Error ( await response . text ( ) ) ;
3636} ;
3737
38+ const createDescription = ( description ) => ( {
39+ ...description ,
40+ type : "doc" ,
41+ content : description . content . filter (
42+ ( content ) => content . type !== "mediaSingle"
43+ ) ,
44+ } ) ;
45+
3846const cloneIssue = async ( issue , fields ) => {
3947 const bodyData = {
4048 fields : {
@@ -48,6 +56,9 @@ const cloneIssue = async (issue, fields) => {
4856 "labels" ,
4957 ] ) ,
5058 ...fields ,
59+ description : issue . fields . description
60+ ? createDescription ( issue . fields . description )
61+ : null ,
5162 } ,
5263 update : { } ,
5364 } ;
@@ -96,6 +107,29 @@ const changeStatusDoneIssue = async (issueIdOrKey) => {
96107 if ( response . status !== 204 ) throw new Error ( await response . text ( ) ) ;
97108} ;
98109
110+ const linkCloneIssueToParent = async ( issueKey , parentKey ) => {
111+ const bodyData = {
112+ type : { id : "10006" } , // This is id for split from
113+ inwardIssue : { key : parentKey } ,
114+ outwardIssue : { key : issueKey } ,
115+ } ;
116+
117+ const response = await api . asApp ( ) . requestJira ( route `/rest/api/3/issueLink` , {
118+ method : "POST" ,
119+ headers : {
120+ Accept : "application/json" ,
121+ "Content-Type" : "application/json" ,
122+ } ,
123+ body : JSON . stringify ( bodyData ) ,
124+ } ) ;
125+
126+ console . log (
127+ `linkCloneIssueToParent Response: ${ response . status } ${ response . statusText } `
128+ ) ;
129+
130+ if ( response . status !== 201 ) throw new Error ( await response . text ( ) ) ;
131+ } ;
132+
99133const handleSplit = async ( issueIdOrKey : string ) => {
100134 const issue = await getIssue ( issueIdOrKey ) ;
101135
@@ -108,16 +142,22 @@ const handleSplit = async (issueIdOrKey: string) => {
108142 Number ( issue . fields [ CONFIGS . STORY_POINT_FIELD_NAME ] ?? 0 ) - nextStoryPoint ;
109143
110144 if ( newStoryPoint > 0 ) {
145+ const sprints = issue . fields [ CONFIGS . SPRINT_FIELD_NAME ] ;
146+ const activeSprint = sprints ?. find (
147+ ( sprint ) => sprint . state === "active"
148+ ) ?. id ;
149+
111150 const cloned = await cloneIssue ( issue , {
112151 ...( ! issue . fields . issuetype . subtask && {
113- [ CONFIGS . SPRINT_FIELD_NAME ] :
114- issue . fields [ CONFIGS . SPRINT_FIELD_NAME ] ?. [ 0 ] ?. id ,
152+ // Note this is a subtask and subtasks cannot be associated to a sprint. It's associated to the same sprint as its parent.
153+ [ CONFIGS . SPRINT_FIELD_NAME ] : activeSprint ,
115154 } ) ,
116155 [ CONFIGS . STORY_POINT_FIELD_NAME ] : newStoryPoint ,
117156 summary : `${ issue . fields . summary } - SPLIT` ,
118157 } ) ;
119158
120159 await changeStatusDoneIssue ( cloned . id ) ;
160+ await linkCloneIssueToParent ( cloned . key , issueIdOrKey ) ;
121161 }
122162
123163 await updateIssue ( issue . id , {
0 commit comments