Skip to content

Conversation

@cardil
Copy link

@cardil cardil commented Jul 26, 2023

Changes

  • Listing merged pull requests on Github
  • Listing merged merge requests on Gitlab

@psss
Copy link
Owner

psss commented Jul 27, 2023

Thanks for the pull request. Actually, the PullRequestsClosed stats are intended for listing merged pull requests:

* Pull requests closed on github: 9
    * teemtee/tmt#2221 - Fix test checking custom destination for libraries
    * teemtee/tmt#2216 - Create plans to cover individual step features
    * teemtee/tmt#2206 - Group discover/fmf options, improve wording a bit
    * teemtee/tmt#2203 - Add template option to polarion report
    * teemtee/tmt#2178 - Add cache_property for things that are generated...
    * teemtee/tmt#2173 - Simplify public git conversion with a declarative list
    * teemtee/tmt#2172 - Clean up logging in `tmt.utils.create_directory()`
    * teemtee/tmt#2171 - Spec-based container becomes generic over input...
    * teemtee/tmt#2160 - Move test framework code into distinct framework...

* Pull requests reviewed on github: 6
    * teemtee/tmt#2203 - Add template option to polarion report
    * teemtee/tmt#2178 - Add cache_property for things that are generated...
    * teemtee/tmt#2173 - Simplify public git conversion with a declarative list
    * teemtee/tmt#2172 - Clean up logging in `tmt.utils.create_directory()`
    * teemtee/tmt#2171 - Spec-based container becomes generic over input...
    * teemtee/tmt#2160 - Move test framework code into distinct framework...

* Merged pull requests on github: 3
    * teemtee/tmt#2221 - Fix test checking custom destination for libraries
    * teemtee/tmt#2216 - Create plans to cover individual step features
    * teemtee/tmt#2206 - Group discover/fmf options, improve wording a bit

Not sure how exactly the query author:{0}+merged:{1}..{2} works but definitely some of the pull requests merged by me during this week are not listed. See above.

@2uasimojo
Copy link

I'll say that I don't understand the logic behind "closed". When I use --github-pull-requests-closed the list doesn't seem to include any pull requests I authored. What I want to see (non-exclusively) is pull requests I worked on (authored or co-authored) that have merged. If this PR makes that possible, I'm all for it.

@cardil
Copy link
Author

cardil commented Nov 16, 2023

PR can be closed because of being merged or declined. This takes just the successful PRs.

@psss
Copy link
Owner

psss commented Jan 3, 2024

I'll say that I don't understand the logic behind "closed". When I use --github-pull-requests-closed the list doesn't seem to include any pull requests I authored. What I want to see (non-exclusively) is pull requests I worked on (authored or co-authored) that have merged. If this PR makes that possible, I'm all for it.

Pull requests authored by a user are covered by pull-requests-created. The intention behind the pull-requests-closed stat was to give the credit to the person who took care of merging the pull request. This can cover making sure that tests passed and whatever action or process is agreed in the project. Such person should be set as the pull request assignee. Do you propose a different approach?

PR can be closed because of being merged or declined. This takes just the successful PRs.

Understood. It might make sense to separate closed (without merge) and merged pull requests. However, we need to make sure the stat is working as expected. As mentioned in the comment above, some of the pull requests merged by me in the given time frame are not reported by the new stat. Could you please, have a look into that?

@2uasimojo
Copy link

Hi @psss!

Pull requests authored by a user are covered by pull-requests-created. The intention behind the pull-requests-closed stat was to give the credit to the person who took care of merging the pull request. This can cover making sure that tests passed and whatever action or process is agreed in the project. Such person should be set as the pull request assignee. Do you propose a different approach?

I think of the assignee as the reviewer*. I dig the idea of did having a knob to report all the PRs I reviewed. Useful subsets would be:

  • PR is still open (my "review queue"), possibly reporting how many reviews I've already left on it.
  • PR was closed because merged.
  • PR was closed without merge.

--pull-requests-created is really great... but it would be really useful to see a similar breakdown for those, which I think was the intention behind this PR.

Having worked on CLIs for more than 20y, I appreciate that you may not want to maintain a massive proliferation of flags. That said, I could envision the following non-mutually-exclusive options that could be used in conjunction with all/most of the --github-* ones:

  • --open (n/a -- or just a guaranteed empty set -- for --github-*-closed)
  • --merged
  • --abandoned

...where the default is --open --merged --abandoned

I haven't thought through whether/how these could also apply to --jira-*, but it could be similar.

*I imagine different shops use different processes, so this may not apply universally, but this is how it's done at Red Hat, at least in the OpenShift org, so I know it's not just me :)

@psss
Copy link
Owner

psss commented Jan 3, 2024

I think of the assignee as the reviewer*.

Well, for reviewers there's a dedicated field, right? I would not suggest to duplicate the meaning.

  • PR is still open (my "review queue"), possibly reporting how many reviews I've already left on it.

Just to clarify, the existing pull-requests-reviewed stat does not cover this use case? Unfortunately, the api for reviewed pull reuqests does not always produce correct results (reported the issue several years ago but no progress on that). So I'm not sure how much this can be improved.

  • PR was closed because merged.

+1 for having pull-requests-merged

  • PR was closed without merge.

Your suggested name pull-requests-abandoned makes it less ambiguous, so +1 for this as well.

@2uasimojo
Copy link

I think of the assignee as the reviewer*.

Well, for reviewers there's a dedicated field, right? I would not suggest to duplicate the meaning.

Mm, fair point. The difference being that any schmo can leave a review, whereas in our process the assignee's reviews are the "important" ones -- specifically the ones that the author expects to move the PR toward getting merged. I guess the subtleties of different processes come into play here... but empirically having separate flags for "assigned" vs "reviewed" PRs would give users the flexibility to report in whatever way is most appropriate for them.

  • PR is still open (my "review queue"), possibly reporting how many reviews I've already left on it.

Just to clarify, the existing pull-requests-reviewed stat does not cover this use case?

If I could further filter by open/abandoned/merged, I would think so, yes.

@cardil
Copy link
Author

cardil commented Jan 8, 2024

@psss As mentioned in the #311 (comment), some of the pull requests merged by me in the given time frame are not reported by the new stat. Could you please, have a look into that?

This is straightforward. The -merged is reporting only the PRs you have authored/created, and then it was merged.

The -closed also lists the PRs authored/created by other people, you have approved. That's different.

I need the merged PR (authored by me), as I report the code I, personally, contributed.

@psss
Copy link
Owner

psss commented Jan 8, 2024

I need the merged PR (authored by me), as I report the code I, personally, contributed.

Isn't the credit for authoring a pull request covered by pull-requests-created? What is the work you want to track if you don't review and don't merge the pull request? I would say the contribution of the author is to create the pull request.

@cardil
Copy link
Author

cardil commented Jan 9, 2024

@psss Isn't the credit for authoring a pull request covered by pull-requests-created? What is the work you want to track if you don't review and don't merge the pull request? I would say the contribution of the author is to create the pull request.

The created, might not be merged. So, created contain 3 types: ongoing PRs, successful, and dropped. I just want successful ones, which I've created - merged. Also, the time is important. Creation time != merge time. I want the merge time.

@psss
Copy link
Owner

psss commented Oct 4, 2024

Thanks much for the clarification and sorry for the late response. So it's about getting the work until the finish (merging) and the date is clearly different. Makes sense now. Let's do it as you suggest. Could you please rebase on the latest main?

@psss psss changed the title [WIP] 💝 Listing Merged PRs for Github and Gitlab Support merged pull requests for github and gitlab Oct 4, 2024
@psss psss self-assigned this Oct 4, 2024
@psss psss added this to the 0.22 milestone Oct 4, 2024
@sandrobonazzola
Copy link
Collaborator

Can you please rebase?

@psss psss removed this from the 0.22 milestone Jun 3, 2025
@cardil cardil marked this pull request as ready for review November 17, 2025 18:05
@cardil
Copy link
Author

cardil commented Nov 17, 2025

@sandrobonazzola: Can you please rebase?

Done. Sorry for being inactive on this!

Copy link
Collaborator

@sandrobonazzola sandrobonazzola left a comment

Choose a reason for hiding this comment

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

The GitHub part looks good for merging. Some questions on the GitLab one.

Other questions:

  1. Should we filter by merge date or update date? The PR discussion suggests merge date, but the implementation seems to use update date.
  2. Should we add unit tests similar to the existing GitLab tests?

'author_username': username,
'state': state,
'updated_after': since,
'updated_before': until
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it intentional not setting get_all_results=True here?
Only the first page of results will be fetched here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, has the GitLab global merge_requests endpoint been tested with a real token? Does it work for all users or only admins?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for catching this! I forgot about pagination. I've fixed this by adding get_all_results=True to the get_user_mr() method call.

The /api/v4/merge_requests endpoint is accessible to any authenticated user and respects their visibility permissions - users will only see MRs they have access to view.

Yes, I tested this on a real Gitlab instance. In fact, I've been using this branch for years now! 😆

super().__init__(data, parent, set_id)

def _get_title(self):
return self.data['title']
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't self.data['target_title'] available for MergeRequests?

Copy link
Author

Choose a reason for hiding this comment

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

IMHO, the MergedRequest class is necessary because of data structure differences between the global merge_requests API and the events API:

  • Global API (used by get_user_mr()): Returns MR objects directly with fields like iid and title
  • Events API (used by other MergeRequest stats): Returns event objects with nested fields like target_id and target_title

I've added detailed comments explaining this in the code. The MergedRequest class handles these differences by:

  • Taking iid directly from the data instead of making an extra API call
  • Using data['title'] instead of data['target_title']

Without this class, we'd need to modify the base Issue class to handle both data formats, which would complicate the code.

Copy link
Author

@cardil cardil Nov 18, 2025

Choose a reason for hiding this comment

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

Take a look at 8f5e5ee. I found, that the Markdown formatting requires some params in data, so I remapped the param, and so the _get_title() isn't needed anymore.

@bsipocz
Copy link

bsipocz commented Nov 18, 2025

In its current form this should close #371

@cardil
Copy link
Author

cardil commented Nov 18, 2025

@sandrobonazzola:

  • Should we filter by merge date or update date? The PR discussion suggests merge date, but the implementation seems to use update date.

That's right. I'll update the code to use the merge date. Those two dates are often the same, but the MR might be updated after it's merged, so yes.

  • Should we add unit tests similar to the existing GitLab tests?

Yep, I'll add those...

@cardil
Copy link
Author

cardil commented Nov 18, 2025

@cardil: I'll update the code to use the merge date.

@cardil: Yep, I'll add those...

Both fixed in dd7c2d5

@cardil
Copy link
Author

cardil commented Nov 19, 2025

The readthedocs #30370221 failure was likely due to yesterday's Github outage: https://www.githubstatus.com/incidents/5q7nmlxz30sk

Filter by merged_at timestamp (not updated_at) and add tests for both GitLab and GitHub merge-requests-merged functionality.
Transform MR data structure to include target_title and target_type
fields expected by parent Issue class, eliminating the need for
method overrides.
@kwk
Copy link
Collaborator

kwk commented Nov 20, 2025

Maybe this was already asked. If I were to merge this very PR I suppose it will not show up in the list because I'm not the author, right? Is that what we want? I think there's value in both, PRs / MRs that were merged on your behalf or those that you've merged yourself.

@cardil
Copy link
Author

cardil commented Nov 20, 2025

Maybe this was already asked. If I were to merge this very PR I suppose it will not show up in the list because I'm not the author, right? Is that what we want? I think there's value in both, PRs / MRs that were merged on your behalf or those that you've merged yourself.

This PR is adding -merged flavor, which means: "You created the PR, and it was merged". Someone else might have authored the commits. It doesn't matter who clicks the merge button for this PR. PR author != commit author != commit commiter.

Usually in open-source you can't merge PRs yourself. And if you do, this PR is also the thing you want: the work you proposed, and then it was merged.

You want to list the PRs you merged, even though you are not the author of them? If so, this PR doesn't do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants