-
Notifications
You must be signed in to change notification settings - Fork 115
Jira issues with worklogs #429
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6e2c325
Jira issues with worklogs
kwk 9cc1096
Fixup for SyntaxError: f-string: unmatched '['
kwk df46556
Fixup
kwk 69283b8
Fix since / until
kwk 2f550f8
Introduce worklog_enabled option (default off)
kwk 2f265d5
Add tests
kwk 9f546ed
Remove commented out code
kwk a37383f
Remove commented out code
kwk 67678e0
Fix typo: workLogDate -> worklogDate
kwk 57134e6
Treat optional comment field more carefully
kwk fedb6e8
Treat time_spent_value field more carefully
kwk 619a347
Treat worklogs field more carefully
kwk 51b9adb
chaining date comparison
kwk e442fb4
Fix typo: filterting -> filtering
kwk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,15 @@ | |
|
|
||
| import logging | ||
| import os | ||
| import re | ||
| import tempfile | ||
|
|
||
| import pytest | ||
| from _pytest.logging import LogCaptureFixture | ||
|
|
||
| import did.base | ||
| import did.cli | ||
| from did.plugins.jira import JiraStats | ||
| from did.plugins.jira import JiraStats, JiraWorklog | ||
|
|
||
| CONFIG = """ | ||
| [general] | ||
|
|
@@ -253,3 +254,133 @@ def assert_conf_error(config, expected_error=did.base.ReportError): | |
| did.base.Config(config) | ||
| with pytest.raises(expected_error): | ||
| JiraStats("jira") | ||
|
|
||
|
|
||
| def has_worklog_stat() -> bool: | ||
| """ Returns true if a fresh initiated JiraStats | ||
| object would have a JiraWorklog object """ | ||
| stats = JiraStats("jira") | ||
| for stat in stats.stats: | ||
| if isinstance(stat, JiraWorklog): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( # type: ignore[misc] | ||
| ("config_str", "expected_worklog_enable"), | ||
| [ | ||
| (f""" | ||
| {CONFIG} | ||
| """, False), | ||
| (f""" | ||
| {CONFIG} | ||
| worklog_enable = on | ||
| """, True), | ||
| (f""" | ||
| {CONFIG} | ||
| worklog_enable = off | ||
| """, False), | ||
| ], | ||
| ) | ||
| def test_worklog_enabled( | ||
| config_str: str, | ||
| expected_worklog_enable: bool, | ||
| ) -> None: | ||
| """ Tests default and explicit behaviour for worklog_enable """ | ||
| did.base.Config(config_str) | ||
| assert has_worklog_stat() == expected_worklog_enable | ||
|
|
||
|
|
||
| def get_named_stat(options: str): | ||
| """ | ||
| Retrieve the statistics by option name. | ||
| """ | ||
| for stat in did.cli.main(f"{options}")[0][0].stats[0].stats: | ||
| if stat.option in options: | ||
| assert stat.stats is not None | ||
| return stat.stats | ||
| pytest.fail(reason=f"No stat found with options {options}") | ||
| return None | ||
|
|
||
|
|
||
| def test_worklog_against_real_jira_instance() -> None: | ||
| """ Check that worklogs are printed for matching issues """ | ||
| # I've searched a public Jira instance and found this issue | ||
| # that has worklog entries: | ||
| # https://issues.apache.org/jira/browse/HIVE-21563 | ||
| # The user "githubbot" has more entries in other issues | ||
| # that we've limited to certain day. | ||
| did.base.Config(""" | ||
| [general] | ||
| email = [email protected] | ||
| width = 500 | ||
| [jira] | ||
| type = jira | ||
| prefix = HIVE | ||
| project = HIVE | ||
| login = githubbot | ||
| url = https://issues.apache.org/jira/ | ||
| worklog_enable = on | ||
| """) | ||
| options = "--jira-worklog --since 2021-05-07 --until 2021-05-07 --verbose" | ||
| stats = get_named_stat(options) | ||
| expectations = [ | ||
| { | ||
| "id": "HIVE-25095", | ||
| "worklog_snippets": [ | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "ujc714 opened a new pull request #2255:", | ||
| ] | ||
| }, | ||
| { | ||
| "id": "HIVE-25089", | ||
| "worklog_snippets": [ | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "kasakrisz merged pull request #2241:", | ||
| ]}, | ||
| { | ||
| "id": "HIVE-25071", | ||
| "worklog_snippets": [ | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "kasakrisz commented on a change in pull request #2231:", | ||
| ]}, | ||
| { | ||
| "id": "HIVE-25046", | ||
| "worklog_snippets": [ | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "zabetak commented on a change in pull request #2205:" | ||
| ] | ||
| }, { | ||
| "id": "HIVE-23756", | ||
| "worklog_snippets": [ | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "scarlin-cloudera closed pull request #2253:", | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "scarlin-cloudera opened a new pull request #2254:" | ||
| ] | ||
| }, { | ||
| "id": "HIVE-21563", | ||
| "worklog_snippets": [ | ||
| "* Worklog: Friday, May 07, 2021 (10m)", | ||
| "sunchao merged pull request #2251:", | ||
| ]}, | ||
| ] | ||
| assert len(expectations) == len(stats) | ||
| for i, exp in enumerate(expectations): | ||
| stat_str = str(stats[i]) | ||
|
|
||
| # Check that the issue with the given ID was found | ||
| id_pattern = f"{exp["id"]} \\S+" | ||
| regex = re.compile(id_pattern) | ||
| assert regex | ||
| assert regex.match(stat_str) | ||
|
|
||
| # Check that for each issue we find the expected | ||
| # worklog snippets one after the next | ||
| start = 0 | ||
| for worklog_snippet in exp["worklog_snippets"]: | ||
| new_start = stat_str.find(worklog_snippet, start) | ||
| assert new_start > 0, (f"worklog_snippet '{worklog_snippet}' " | ||
| "not found in stat string from position " | ||
| "{start}: {stat_str}") | ||
| start = new_start | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.