Skip to content

Handle missing active milestones#152

Open
subhajitlucky wants to merge 2 commits into
zigcBenx:masterfrom
subhajitlucky:handle-no-milestones-47
Open

Handle missing active milestones#152
subhajitlucky wants to merge 2 commits into
zigcBenx:masterfrom
subhajitlucky:handle-no-milestones-47

Conversation

@subhajitlucky
Copy link
Copy Markdown

Fixes #47

Summary

  • return None when the GitLab project has no active milestones during manual milestone selection
  • add regression coverage for the empty active-milestones case

Verification

  • python3 -m unittest tests.test_milestones_empty -v
  • python3 -m unittest discover -v
  • python3 -m compileall gitHappens.py tests
  • git diff --check

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent failures when a GitLab group has no “active for today” milestones by returning None from milestone auto-selection, and adds a regression test for the empty active-milestones case (Fixes #47).

Changes:

  • Update list_milestones(current=True) to return None when no active milestone matches the current date window.
  • Add a unit test covering the empty “active-for-today” milestone scenario.
  • Add tests/__init__.py to make tests a package.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
gitHappens.py Returns None when no current active milestone is found (and includes a minor EOF formatting change).
tests/test_milestones_empty.py Adds regression coverage for the empty current-milestone case via a dynamic module load and subprocess mocking.
tests/__init__.py Introduces a package marker for the tests directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gitHappens.py
Comment on lines 102 to 107
if start_date and due_date and start_date <= today and due_date >= today:
active_milestones.append(milestone)
active_milestones.sort(key=lambda x: x['due_date'])
if not active_milestones:
return None
return active_milestones[0]
Comment thread gitHappens.py
Comment on lines 104 to +106
active_milestones.sort(key=lambda x: x['due_date'])
if not active_milestones:
return None
Comment on lines +11 to +27
root = Path(__file__).resolve().parents[1]
config_dir = root / "configs"
config_dir.mkdir(exist_ok=True)
(config_dir / "config.ini").write_text(
"[DEFAULT]\n"
"base_url=https://gitlab.example\n"
"group_id=42\n"
"custom_template=Custom\n"
"GITLAB_TOKEN=test-token\n"
"squash_commits=true\n"
"delete_branch_after_merge=true\n",
encoding="utf-8",
)
(config_dir / "templates.json").write_text(
'{"templates": [], "reviewers": []}',
encoding="utf-8",
)
Comment thread tests/test_milestones_empty.py Outdated
Comment on lines +29 to +38
sys.modules["inquirer"] = types.SimpleNamespace(
prompt=mock.Mock(),
Text=lambda *args, **kwargs: ("Text", args, kwargs),
List=lambda *args, **kwargs: ("List", args, kwargs),
Checkbox=lambda *args, **kwargs: ("Checkbox", args, kwargs),
)

spec = importlib.util.spec_from_file_location("gitHappens_under_test", root / "gitHappens.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
@subhajitlucky
Copy link
Copy Markdown
Author

Updated this PR to address the review comments:

  • added get_milestone_id() so main() omits milestone_id when no current active milestone exists instead of indexing None
  • added regression coverage for that call path
  • scoped the inquirer module stub with mock.patch.dict
  • preserved/restored local config files around the dynamic import test fixture

Verification after the update:

  • python3 -m unittest tests.test_milestones_empty -v
  • python3 -m unittest discover -v
  • python3 -m compileall gitHappens.py tests
  • git diff --check

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.

Create issue fails if no milestones available 🔥

2 participants