Skip to content

Commit

Permalink
Add closed field
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 3, 2023
1 parent a378005 commit b730353
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ List of soft-failures for [os-autoinst-distri-opensuse](https://github.com/os-au
usage: bugme.py [-h] [-c CREDS] [-f FIELDS]
[-l {none,debug,info,warning,error,critical}]
[-o {text,html,json}] [-r]
[-s {tag,url,status,created,updated,assignee,creator}]
[-s {tag,url,status,created,updated,closed,assignee,creator}]
[-S STATUS] [-t TIME_FORMAT] [--version]
[url ...]
Expand All @@ -34,14 +34,14 @@ options:
-o {text,html,json}, --output {text,html,json}
output type (default: text)
-r, --reverse reverse sort (default: False)
-s {tag,url,status,created,updated,assignee,creator}, --sort {tag,url,status,created,updated,assignee,creator}
-s {tag,url,status,created,updated,closed,assignee,creator}, --sort {tag,url,status,created,updated,closed,assignee,creator}
sort key (default: None)
-S STATUS, --status STATUS
filter by status (may be specified multiple times) (default: None)
-t TIME_FORMAT, --time TIME_FORMAT
--version show program's version number and exit
output fields for --fields: tag,url,status,created,updated,title,assignee,creator
output fields for --fields: tag url status created updated closed title assignee creator
```

## Example
Expand Down
20 changes: 15 additions & 5 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parse_args() -> argparse.Namespace:
"""
argparser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
epilog="output fields for --fields: tag,url,status,created,updated,title,assignee,creator",
epilog="output fields for --fields: tag url status created updated closed title assignee creator",
)
argparser.add_argument(
"-c",
Expand Down Expand Up @@ -65,7 +65,16 @@ def parse_args() -> argparse.Namespace:
argparser.add_argument(
"-s",
"--sort",
choices=["tag", "url", "status", "created", "updated", "assignee", "creator"],
choices=[
"tag",
"url",
"status",
"created",
"updated",
"closed",
"assignee",
"creator",
],
help="sort key",
)
argparser.add_argument(
Expand Down Expand Up @@ -102,7 +111,7 @@ def get_issues(
MyBugzilla: {
"force_rest": True,
"sslverify": os.environ.get("REQUESTS_CA_BUNDLE", True),
"include_fields": "id assigned_to creator status summary creation_time last_change_time".split()
"include_fields": "id assigned_to creator status summary creation_time last_change_time is_open".split()
if output_type != "json"
else None,
},
Expand Down Expand Up @@ -225,8 +234,9 @@ def print_issues( # pylint: disable=too-many-arguments

fields = {field: len(field) for field in output_format.split(",")}
for issue in issues:
issue.created = dateit(issue.created, time_format)
issue.updated = dateit(issue.updated, time_format)
for field in "created", "updated", "closed":
if field in fields:
issue[field] = dateit(issue[field], time_format)
issue.files = xtags.get(issue.tag, [])
for info in issue.files:
info["date"] = dateit(info["date"], time_format) # type: ignore
Expand Down
7 changes: 7 additions & 0 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def _to_issue(self, info: Any) -> Issue:
creator=info.creator,
created=utc_date(info.creation_time),
updated=utc_date(info.last_change_time),
closed=utc_date(info.last_change_time if not info.is_open else None),
status=info.status.upper().replace(" ", "_"),
title=info.summary,
raw=info.get_raw_data(),
Expand Down Expand Up @@ -320,6 +321,7 @@ def _to_issue(self, info: Any, repo: str) -> Issue:
creator=info.user.login,
created=utc_date(info.created_at),
updated=utc_date(info.updated_at),
closed=utc_date(info.closed_at),
status=info.state.upper().replace(" ", "_"),
title=info.title,
raw=info.raw_data,
Expand Down Expand Up @@ -377,6 +379,7 @@ def _to_issue(self, info: Any, repo: str) -> Issue:
creator=info.author["name"],
created=utc_date(info.created_at),
updated=utc_date(info.updated_at),
closed=utc_date(info.closed_at),
status=info.state.upper().replace(" ", "_"),
title=info.title,
raw=info.asdict(),
Expand Down Expand Up @@ -424,6 +427,7 @@ def _to_issue(self, info: Any) -> Issue:
creator=info.author.name,
created=utc_date(info.created_on),
updated=utc_date(info.updated_on),
closed=utc_date(info.closed_on),
status=info.status.name.upper().replace(" ", "_"),
title=info.subject,
raw=info.raw(),
Expand Down Expand Up @@ -471,6 +475,7 @@ def _to_issue(self, info: Any) -> Issue:
creator=info["fields"]["creator"]["name"],
created=utc_date(info["fields"]["created"]),
updated=utc_date(info["fields"]["updated"]),
closed=utc_date(info["fields"]["resolutiondate"]),
status=info["fields"]["status"]["name"].upper().replace(" ", "_"),
title=info["fields"]["summary"],
raw=info,
Expand Down Expand Up @@ -552,6 +557,7 @@ def _to_issue(self, info: Any, repo: str) -> Issue:
creator=info["user"]["login"],
created=utc_date(info["created_at"]),
updated=utc_date(info["updated_at"]),
closed=utc_date(info["closed_at"]),
status=info["state"].upper().replace(" ", "_"),
title=info["title"],
raw=info,
Expand All @@ -576,6 +582,7 @@ def _to_issue(self, info: Any, repo: str) -> Issue:
creator=info["user"]["name"],
created=utc_date(info["date_created"]),
updated=utc_date(info["last_updated"]),
closed=utc_date(info["closed_at"]),
status=info["status"].upper().replace(" ", "_"),
title=info["title"],
raw=info,
Expand Down
6 changes: 5 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ def dateit(date: datetime, time_format: str = "%a %b %d %H:%M:%S %Z %Y") -> str:
"""
Return date in desired format
"""
if date == datetime.max.replace(tzinfo=utc):
return "not yet"
date = date.astimezone()
if time_format == "timeago":
return timeago(date)
return date.strftime(time_format)


def utc_date(date: str | datetime) -> datetime:
def utc_date(date: str | datetime | None) -> datetime:
"""
Return UTC normalized datetime object from date
"""
if date is None:
return datetime.max.replace(tzinfo=utc)
if isinstance(date, str):
if date.isdigit():
date = datetime.fromtimestamp(int(date))
Expand Down

0 comments on commit b730353

Please sign in to comment.