Skip to content

feat: introduce related_issues to merge requests #2996

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 11 commits into from
Sep 24, 2024
Merged

Conversation

xakepnz
Copy link
Contributor

@xakepnz xakepnz commented Sep 23, 2024

Changes

  • This PR introduces related_issues for the merge_requests object, returning a list of all related issues.

Context

GitLab released related_issues (official docs), an endpoint which collects all issues that relate to the current MR. This can be from:

  • commit messages on the MR that contain issue links
  • issue links commented in the MR
  • issue links in the title of the MR
  • issues created from discussions in the MR

See the change introduced: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/155422

PoC:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://127.0.0.1:3000/api/v4/projects/7/merge_requests/1/related_issues"

Documentation and testing

Both docs & tests updated

Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated:

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your contribution @xakepnz!

I just left a few initial comments to get tests green hopefully. Let me know if anything's unclear.

@xakepnz xakepnz marked this pull request as draft September 23, 2024 10:54
Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.61%. Comparing base (a2ab54c) to head (412d92d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2996   +/-   ##
=======================================
  Coverage   96.61%   96.61%           
=======================================
  Files          95       95           
  Lines        6080     6087    +7     
=======================================
+ Hits         5874     5881    +7     
  Misses        206      206           
Flag Coverage Δ
api_func_v4 82.58% <42.85%> (+0.06%) ⬆️
cli_func_v4 82.89% <42.85%> (-0.05%) ⬇️
unit 88.74% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
gitlab/v4/objects/merge_requests.py 89.67% <100.00%> (+0.48%) ⬆️

@xakepnz
Copy link
Contributor Author

xakepnz commented Sep 23, 2024

Thanks a lot for your contribution @xakepnz!

I just left a few initial comments to get tests green hopefully. Let me know if anything's unclear.

Hey @nejch, thanks for the quick replies! - I ended up reverting my test before seeing your suggestions. So i've re-added it and i'm still working on Mocking the calls to /related_issues

You're correct, the response from GitLab API is a list of dicts containing a lot more than just the issue id's.

I'll keep working on this to try and pass CI tests.

xakepnz and others added 8 commits September 24, 2024 00:37
Add related_issues mock endpoint call and resp test
Update title attr and ensure GET request is mocked
Ensure related_issues URL calls match expected mocks
Ensure related_issues mock request matches the same project & MR mock request
RESTObjectList iters an expected ProjectIssue obj
@xakepnz xakepnz marked this pull request as ready for review September 23, 2024 12:52
@xakepnz xakepnz requested a review from nejch September 23, 2024 12:52
@xakepnz
Copy link
Contributor Author

xakepnz commented Sep 23, 2024

Hey @nejch should be all set now thanks!

need-sleep

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

Thanks again for your contribution @xakepnz, LGTM now!

These days I'd probably prefer a manager with .list() which would also solve your next(iter(..)) issues, but it's a bit of overhead in the code and I see we already have the same approach for commits, closes_issues etc.

I'll squash the commits just so we have a clean history here.

@nejch nejch merged commit 174d992 into python-gitlab:main Sep 24, 2024
18 checks 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