Skip to content

Commit 9476b1b

Browse files
authored
INFRADEV-15413: Add an option in scottypy to link beam to Jira ticket (#37)
* INFRADEV-15413: Add associated issue creation to beam_up * INFRADEV-15413: Add associated issue to up local command * INFRADEV-15413: Associate the created issue to the beam * INFRADEV-15413: Add check for associated_issue is not None * INFRADEV-15413: Don't hardcode tracker name * INFRADEV-15413: Fix typo * INFRADEV-15413: Fix format * INFRADEV-15413: Change type to int from str
1 parent 1f1ea94 commit 9476b1b

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

scottypy/app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,28 @@ def up() -> None:
196196
@up.command()
197197
@click.argument("directory")
198198
@click.option("--url", default=_get_url, help="Base URL of Scotty")
199+
@click.option("--issue", help="Associated issue ticket name")
200+
@click.option("--tracker", default="JIRA", help="Issue tracker name")
199201
@click.option(
200202
"-t",
201203
"--tag",
202204
"tags",
203205
multiple=True,
204206
help="Tag to be associated with the beam. Can be specified multiple times",
205207
)
206-
def local(directory: str, url: str, tags: typing.List[str]) -> None:
208+
def local(
209+
directory: str, url: str, tags: typing.List[str], issue: str, tracker: str
210+
) -> None:
207211
logging.basicConfig(
208212
format="%(name)s:%(levelname)s:%(message)s", level=logging.DEBUG
209213
)
210214

211215
scotty = Scotty(url)
212216

213217
click.echo("Beaming up {}".format(directory))
214-
beam_id = scotty.beam_up(directory, tags=tags)
218+
beam_id = scotty.beam_up(
219+
directory, tags=tags, associated_issue=issue, tracker_name=tracker
220+
)
215221
click.echo("Successfully beamed beam #{}".format(beam_id))
216222

217223

scottypy/beam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def set_comment(self, comment: str) -> None:
128128
raise_for_status(response)
129129
self._comment = comment
130130

131-
def set_issue_association(self, issue_id: str, associated: bool) -> None:
131+
def set_issue_association(self, issue_id: int, associated: bool) -> None:
132132
raise_for_status(
133133
self._scotty.session.request(
134134
"POST" if associated else "DELETE",

scottypy/scotty.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,17 @@ def beam_up(
199199
beam_type: typing.Optional[str] = None,
200200
tags: typing.Optional[typing.List[str]] = None,
201201
return_beam_object: bool = False,
202+
tracker_name: str = "JIRA",
203+
associated_issue: typing.Optional[str] = None,
202204
) -> typing.Union["Beam", int]:
203205
"""Beam up the specified local directory to Scotty.
204206
205207
:param str directory: Local directory to beam.
206208
:param str email: Your email. If unspecified, the initiator of the beam will be anonymous.
207209
:param list tags: An optional list of tags to be associated with the beam.
208210
:param bool return_beam_object: If set to True, return a :class:`.Beam` instance.
211+
:param str associated_issue: An optional associated issue ticket.
212+
:param str tracker_name: Name of the issues tracker.
209213
210214
:return: the beam id."""
211215
if not os.path.exists(directory):
@@ -240,14 +244,22 @@ def beam_up(
240244

241245
beam_data = response.json()
242246
beam_id = beam_data["beam"]["id"] # type: int
247+
beam_obj = Beam.from_json(self, beam_data["beam"])
248+
249+
if associated_issue:
250+
tracker_id = self.get_tracker_id(name=tracker_name)
251+
issue_id = self.create_issue(
252+
tracker_id=tracker_id, id_in_tracker=associated_issue
253+
)
254+
beam_obj.set_issue_association(issue_id=issue_id, associated=True)
243255

244256
combadge = self._get_combadge(combadge_version)
245257
combadge.run(
246258
beam_id=beam_id, directory=directory, transporter_host=transporter_host
247259
)
248260

249261
if return_beam_object:
250-
return Beam.from_json(self, beam_data["beam"])
262+
return beam_obj
251263
else:
252264
return beam_id
253265

0 commit comments

Comments
 (0)