Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate json output #49

Merged

Conversation

bryceharrington
Copy link
Member

Adds preliminary JSON support to ustriage. This adds a --json option which can be used when generating the housekeeping report.

JSON support generally, for the daily triage report and other invocations of ustriage will be added in a separate branch. That will require more extensive refactoring and is beyond the scope of what this branch aims for.

To test this, I've run the following three commands on each commit in the branch:

$ tox
$ python3 -m ustriage
$ python3 -m ustriage --no-show-triage --extended --show-tagged --tag server-todo --json

I've verified 1. tox passes on all commits, 2. the triage reports generate byte-identical output, and 3. the json output is loadable as a valid JSON document (see check-json in housekeeping-tools).

A --json argument is added to make the code print its data in JSON
rather than a tabular report.  One way to run this would be:

  $ python3 -m ustriage --no-show-triage --extended --show-tagged --tag server-todo --json
This provides a way to flatten the bug task objects for outputting to
JSON.

Example output:

[
    {
        "url": "https://pad.lv/2012763",
        "shortlink": "LP: #2012763",
        "number": "2012763",
        "title": "Bug #2012763 in lxd (Ubuntu Jammy): \"qemu-system-amd64 max cpus is too low for latest processors\"",
        "short_title": "qemu-system-amd64 max cpus is too low for latest processors",
        "source_package": "lxd",
        "importance": "Undecided",
        "status": "New",
        "tags": [
            "server-todo",
            "verification-done",
            "verification-done-jammy",
            "verification-done-mantic"
        ],
        "assignee": false
    },
...
]

[squash] json output lint cleanup
Refactor get_flags() to split out the per-flag logic into internal
helper routines that can also be called from to_dict().

With this change, the JSON output now looks like:

    {
        "url": "https://pad.lv/2077036",
        "shortlink": "LP: #2077036",
        "number": "2077036",
        "title": "Bug #2077036 in qemu (Ubuntu): \"powerpc cross tools generate bogus string table\"",
        "short_title": "powerpc cross tools generate bogus string table",
        "source_package": "qemu",
        "importance": "Undecided",
        "status": "Fix Committed",
        "tags": [
            "server-todo"
        ],
        "assignee": "sergiodj",
        "is_maintainer_subscribed": false,
        "is_last_activity_by_maintainer": true,
        "is_updated_recently": true,
        "is_old": false,
        "is_verification_needed": false,
        "is_verification_done": false
    },
Cache some properties that can be parsed from the bug task's url.  This
derives from logic that is used when evaluating status of sibling tasks
to make use of the info in the object itself.

Note that theoretically this could differ from the information if
queried from Launchpad.  The latter would be more canonical, however
doing it this way should be more performant, at least for ustriage's use
case.
Since series is passed to _is_in_unapproved() anyway, we can move the
check for a devel series into it.

[Note that the code is assuming that uploads to the -devel series are
always approved is, which is generally true but may not be universally
true.  Probably not worth worrying about just yet.]
Copy link
Member

@lvoytek lvoytek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me overall, refactor makes sense, JSON keys all look good, and --json arg setup looks good. I just have one optional var name nitpick.

Also I noticed that when there is no assignee to a task, the value becomes false. Since this is being exported to JSON now I think we should probably change that output to None in the assignee() Task function. This would avoid a parsing issue in the case someone has a user id like ~false

ustriage/task.py Show resolved Hide resolved
@bryceharrington bryceharrington merged commit 1900fba into canonical:master Aug 30, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants