Skip to content

Commit 63f6215

Browse files
committed
[CAS-3099] CAS-3099-split-jira-tasks-before-we-close-a-sprint-split
1 parent bcfc9c3 commit 63f6215

2 files changed

Lines changed: 43 additions & 18 deletions

File tree

src/consumer.tsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3846
const 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+
99133
const 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, {

src/index.jsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,11 @@ const getBoardSprints = async (boardId) => {
3939

4040
const App = () => {
4141
const [issues, setIssues] = useState();
42-
const [nextSprintId, setNextSprintId] = useState();;
4342
const [isConfirm, setConfirm] = useState(false);
4443
const [isCompleted, setCompleted] = useState(false);
4544
const [sprints] = useState(async () => await getBoardSprints(CONFIGS.CASHY_BOARD_ID));
4645

47-
const activeSprint = sprints?.find(sprint => sprint.state === 'active')
48-
const activeSprintNumber = Number(activeSprint?.name?.match(/\d+/)?.[0])
49-
const suggestNextSprintId = activeSprintNumber && sprints?.find(sprint => sprint.state === 'future' && Number(sprint.name?.match(/\d+/)?.[0]) === activeSprintNumber + 1)?.id
50-
5146
const handleSubmit = async (v) => {
52-
setNextSprintId(v.nextSprint)
5347
const data = await searchIssues(v.targetSprint)
5448
setIssues(data
5549
.filter(issue =>
@@ -81,7 +75,7 @@ const App = () => {
8175
}
8276

8377
const actionsButtons = [
84-
<Button text="Split tasks" onClick={handleConfirmSplit} disabled={!nextSprintId} />
78+
<Button text="Split tasks" onClick={handleConfirmSplit} />
8579
]
8680

8781
return (
@@ -94,15 +88,6 @@ const App = () => {
9488
<Option defaultSelected={sprint.state === 'active'} label={sprint.name} value={sprint.id} key={sprint.id} />
9589
))}
9690
</Select>
97-
98-
<Select label="Next sprint" name="nextSprint" isRequired>
99-
{sprints
100-
?.filter(sprint => sprint.state !== 'active')
101-
?.map(sprint => (
102-
<Option defaultSelected={sprint.id === suggestNextSprintId} label={sprint.name} value={sprint.id} key={sprint.id} />
103-
))}
104-
</Select>
105-
10691
</Form>
10792

10893

0 commit comments

Comments
 (0)