Skip to content

Commit 62004e9

Browse files
committed
Merge branch 'release/0.26.0'
2 parents 49b4a02 + d1d0602 commit 62004e9

File tree

14 files changed

+200
-98
lines changed

14 files changed

+200
-98
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ${{ matrix.image }}
77
strategy:
88
matrix:
9-
python_version: [3.5, 3.6, 3.7, 3.8]
9+
python_version: [3.6, 3.7, 3.8, 3.9]
1010
image: [ubuntu-18.04]
1111

1212
steps:
@@ -18,8 +18,7 @@ jobs:
1818
- name: Install requirements
1919
run: pip install -e . -r unittests/requirements.txt pylint mypy
2020
- name: Format
21-
if: matrix.python_version == '3.8'
22-
run: pip install black "isort<5" && make format
21+
run: pip install black isort && make format
2322
- name: Lint
2423
run: make lint
2524
- name: Unittest

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ combine_as_imports = true
33
line_length = 100
44
multi_line_output = 3
55
include_trailing_comma = true
6-
known_third_party = capacity
6+
known_third_party = capacity,flask_loopback

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[MESSAGES CONTROL]
2-
disable=R,broad-except,protected-access,unused-argument,redefined-builtin,missing-docstring,invalid-name,ungrouped-imports,wrong-import-order,bad-continuation
2+
disable=R,broad-except,protected-access,unused-argument,redefined-builtin,missing-docstring,invalid-name,ungrouped-imports,wrong-import-order,bad-continuation,consider-using-f-string,unspecified-encoding
33

44
[FORMAT]
55
max-line-length=150

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ default: check
22

33

44
format:
5-
isort -df -rc scottypy unittests
5+
isort --df -rc scottypy unittests
66
isort -c -rc scottypy unittests
7-
black --check scottypy unittests
7+
black --check --diff scottypy unittests
88

99
do_format:
1010
isort -rc scottypy unittests
@@ -14,7 +14,7 @@ test:
1414
pytest unittests/
1515

1616
lint:
17-
MYPYPATH=stubs mypy scottypy --strict
17+
MYPYPATH=stubs mypy scottypy --strict --install-types --non-interactive
1818
pylint --rcfile .pylintrc -j $(shell nproc) scottypy unittests
1919

2020
check: format lint test

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Scotty Client Library
32

43
## Notes For Developers
@@ -7,6 +6,7 @@
76

87
1. Update changelog in `README.md` file
98
1. Run the following:
9+
1010
```
1111
VERSION=...
1212
git flow release start "$VERSION"
@@ -17,37 +17,40 @@ git flow release finish "$VERSION"
1717
git push origin : --tags
1818
```
1919

20-
2120
## ChangeLog
2221

22+
### 0.26.0
23+
24+
- Add option to link beam to issue when uploading a beam
25+
2326
### 0.25.2
2427

25-
* Increase timeout to 30 seconds
28+
- Increase timeout to 30 seconds
2629

2730
### 0.25.1
2831

29-
* Fix get_beams_by_issue so that it will use pagination
32+
- Fix get_beams_by_issue so that it will use pagination
3033

3134
### 0.25.0
3235

33-
* Use combadge v2 by default (which supports windows hosts)
36+
- Use combadge v2 by default (which supports windows hosts)
3437

3538
### 0.24.0
3639

37-
* Add filtering by issue
38-
* Add delete method to beam
40+
- Add filtering by issue
41+
- Add delete method to beam
3942

4043
### 0.23.1
4144

42-
* Provide more information on exceptions
43-
* Add type hinting
44-
* Fix bug with downloading windows paths on linux
45+
- Provide more information on exceptions
46+
- Add type hinting
47+
- Fix bug with downloading windows paths on linux
4548

4649
### 0.22.1
4750

48-
* Fix bug with prefetch and then beam up without explicitly setting version
51+
- Fix bug with prefetch and then beam up without explicitly setting version
4952

5053
### 0.22.0
5154

52-
* Support python3.8
53-
* Support Rust Combadge (v2)
55+
- Support python3.8
56+
- Support Rust Combadge (v2)

scottypy/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.25.2"
1+
__version__ = "0.26.0"

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/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from requests import Session
1313

1414

15-
_CHUNK_SIZE = 1024 ** 2 * 4
15+
_CHUNK_SIZE = 1024**2 * 4
1616
_EPOCH = datetime.utcfromtimestamp(0)
1717

1818

scottypy/scotty.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import abc
22
import errno
3+
import itertools
34
import json
45
import logging
56
import os
@@ -16,7 +17,7 @@
1617
import emport
1718
import requests
1819
from requests.adapters import HTTPAdapter
19-
from requests.packages.urllib3.util.retry import Retry
20+
from requests.packages.urllib3.util.retry import Retry # type: ignore
2021

2122
from .beam import Beam
2223
from .exc import PathNotExists
@@ -26,7 +27,7 @@
2627

2728
_SLEEP_TIME = 10
2829
_NUM_OF_RETRIES = (60 // _SLEEP_TIME) * 15
29-
_TIMEOUT = 5
30+
_TIMEOUT = 30
3031
_DEFAULT_COMBADGE_VERSION = "v2"
3132
logger = logging.getLogger("scotty") # type: logging.Logger
3233

@@ -65,10 +66,11 @@ def from_response(cls, response: requests.Response) -> "CombadgePython":
6566
return cls(emport.import_file(combadge_file.name))
6667

6768
def remove(self) -> None:
68-
os.remove(self._combadge_module.__file__)
69+
if self._combadge_module.__file__ is not None:
70+
os.remove(self._combadge_module.__file__)
6971

7072
def run(self, *, beam_id: int, directory: str, transporter_host: str) -> None:
71-
self._combadge_module.beam_up(beam_id, directory, transporter_host) # type: ignore
73+
self._combadge_module.beam_up(beam_id, directory, transporter_host)
7274

7375

7476
class CombadgeRust(Combadge):
@@ -197,13 +199,17 @@ def beam_up(
197199
beam_type: typing.Optional[str] = None,
198200
tags: typing.Optional[typing.List[str]] = None,
199201
return_beam_object: bool = False,
202+
tracker_name: str = "JIRA",
203+
associated_issue: typing.Optional[str] = None,
200204
) -> typing.Union["Beam", int]:
201205
"""Beam up the specified local directory to Scotty.
202206
203207
:param str directory: Local directory to beam.
204208
:param str email: Your email. If unspecified, the initiator of the beam will be anonymous.
205209
:param list tags: An optional list of tags to be associated with the beam.
206210
: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.
207213
208214
:return: the beam id."""
209215
if not os.path.exists(directory):
@@ -238,14 +244,22 @@ def beam_up(
238244

239245
beam_data = response.json()
240246
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)
241255

242256
combadge = self._get_combadge(combadge_version)
243257
combadge.run(
244258
beam_id=beam_id, directory=directory, transporter_host=transporter_host
245259
)
246260

247261
if return_beam_object:
248-
return Beam.from_json(self, beam_data["beam"])
262+
return beam_obj
249263
else:
250264
return beam_id
251265

@@ -415,14 +429,23 @@ def get_beams_by_issue(self, issue: str) -> typing.List[Beam]:
415429
:param str issue: The name of the issue.
416430
:return: a list of :class:`.Beam` objects.
417431
"""
432+
beams = [] # type: typing.List[Beam]
433+
per_page = 50
434+
for page in itertools.count(1):
435+
response = self._session.get(
436+
"{0}/beams?issue={1}&page={2}&per_page={3}".format(
437+
self._url, issue, page, per_page
438+
),
439+
timeout=_TIMEOUT,
440+
)
441+
raise_for_status(response)
418442

419-
response = self._session.get(
420-
"{0}/beams?issue={1}".format(self._url, issue), timeout=_TIMEOUT
421-
)
422-
raise_for_status(response)
423-
424-
ids = (b["id"] for b in response.json()["beams"])
425-
return [self.get_beam(id_) for id_ in ids]
443+
response_json = response.json()
444+
ids = (b["id"] for b in response_json["beams"])
445+
beams.extend(self.get_beam(id_) for id_ in ids)
446+
if page >= response_json["meta"]["total_pages"]:
447+
break
448+
return beams
426449

427450
def sanity_check(self) -> None:
428451
"""Check if this instance of Scotty is functioning. Raise an exception if something's wrong"""
@@ -491,7 +514,7 @@ def delete_issue(self, issue_id: int) -> None:
491514
def get_issue_by_tracker(
492515
self, tracker_id: int, id_in_tracker: str
493516
) -> typing.Optional[JSON]:
494-
params = {
517+
params: typing.Dict[str, typing.Union[str, int]] = {
495518
"tracker_id": tracker_id,
496519
"id_in_tracker": id_in_tracker,
497520
}

0 commit comments

Comments
 (0)