Skip to content

Commit

Permalink
Add goal field to update/create sprint (#1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbarahal authored Mar 25, 2024
1 parent 4960d8f commit fbdb2bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
16 changes: 12 additions & 4 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5322,6 +5322,7 @@ def update_sprint(
startDate: Any | None = None,
endDate: Any | None = None,
state: str | None = None,
goal: str | None = None,
) -> dict[str, Any]:
"""Updates the sprint with the given values.
Expand All @@ -5330,7 +5331,8 @@ def update_sprint(
name (Optional[str]): The name to update your sprint to
startDate (Optional[Any]): The start date for the sprint
endDate (Optional[Any]): The start date for the sprint
state: (Optional[str]): The start date for the sprint
state: (Optional[str]): The state of the sprint
goal: (Optional[str]): The goal of the sprint
Returns:
Dict[str, Any]
Expand All @@ -5344,6 +5346,8 @@ def update_sprint(
payload["endDate"] = endDate
if state:
payload["state"] = state
if goal:
payload["goal"] = goal

url = self._get_url(f"sprint/{id}", base=self.AGILE_BASE_URL)
r = self._session.put(url, data=json.dumps(payload))
Expand Down Expand Up @@ -5473,6 +5477,7 @@ def create_sprint(
board_id: int,
startDate: Any | None = None,
endDate: Any | None = None,
goal: str | None = None,
) -> Sprint:
"""Create a new sprint for the ``board_id``.
Expand All @@ -5481,6 +5486,7 @@ def create_sprint(
board_id (int): Which board the sprint should be assigned.
startDate (Optional[Any]): Start date for the sprint.
endDate (Optional[Any]): End date for the sprint.
goal (Optional[str]): Goal for the sprint.
Returns:
Sprint: The newly created Sprint
Expand All @@ -5490,14 +5496,16 @@ def create_sprint(
payload["startDate"] = startDate
if endDate:
payload["endDate"] = endDate
if goal:
payload["goal"] = goal

raw_issue_json: dict[str, Any]
raw_sprint_json: dict[str, Any]
url = self._get_url("sprint", base=self.AGILE_BASE_URL)
payload["originBoardId"] = board_id
r = self._session.post(url, data=json.dumps(payload))
raw_issue_json = json_loads(r)
raw_sprint_json = json_loads(r)

return Sprint(self._options, self._session, raw=raw_issue_json)
return Sprint(self._options, self._session, raw=raw_sprint_json)

def add_issues_to_sprint(self, sprint_id: int, issue_keys: list[str]) -> Response:
"""Add the issues in ``issue_keys`` to the ``sprint_id``.
Expand Down
31 changes: 31 additions & 0 deletions tests/resources/test_sprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def setUp(self):
self.board_name = f"board-{uniq}"
self.sprint_name = f"sprint-{uniq}"
self.filter_name = f"filter-{uniq}"
self.sprint_goal = f"goal-{uniq}"

self.board, self.filter = self._create_board_and_filter()

Expand Down Expand Up @@ -76,6 +77,36 @@ def test_create_and_delete(self):
assert sprint.state.upper() == "FUTURE"
# THEN: the sprint .delete() is called successfully

def test_create_with_goal(self):
# GIVEN: The board, sprint name, and goal
# WHEN: we create the sprint
sprint = self.jira.create_sprint(
self.sprint_name, self.board.id, goal=self.sprint_goal
)
# THEN: we create the sprint with a goal
assert isinstance(sprint.id, int)
assert sprint.name == self.sprint_name
assert sprint.goal == self.sprint_goal

def test_update_sprint(self):
# GIVEN: The sprint ID
# WHEN: we update the sprint
sprint = self.jira.create_sprint(
self.sprint_name, self.board.id, goal=self.sprint_goal
)
assert isinstance(sprint.id, int)
assert sprint.name == self.sprint_name
assert sprint.goal == self.sprint_goal
# THEN: the name changes
updated_sprint = self.jira.update_sprint(
sprint.id,
"new_name",
state="future",
startDate="2015-04-11T15:22:00.000+10:00",
endDate="2015-04-20T01:22:00.000+10:00",
)
assert updated_sprint["name"] == "new_name"

def test_add_issue_to_sprint(self):
# GIVEN: The sprint
with self._create_sprint() as sprint:
Expand Down

0 comments on commit fbdb2bf

Please sign in to comment.