Problem/Motivation
I am building a module to help maintainers keep track of all the projects they maintain. I would like to be able to get from the API a response that shows all the projects I am a maintainer of. There is a current endpoint that almost does this:
https://www.drupal.org/jsonapi/node/project_module?filter[uid.name]=andi...
But in this case, it provides a list of the modules a user has created, not all modules for which a user has been listed as a maintainer. In my case, I have been the maintainer of Charts since ~2016, but charts does not show in the link above because I didn't create the original module.
Steps to reproduce
Compare the link above to https://www.drupal.org/u/andileco.
Proposed resolution
Provide a way to filter https://www.drupal.org/jsonapi/node/project_module by all the projects for which a user is listed as a maintainer/co-maintainer.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork drupalorg-3559622
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
fjgarlin commentedRight now this information is not exposed anywhere.
For additional context, it is a table to table migration from D7 drupal.org to modern drupal.org https://git.drupalcode.org/project/drupalorg_migrate/-/blob/1.0.x/migrat...
We will need to decide on the format for this. It might be:
- A view with filters exposed via
jsonapifor example.- A custom endpoint exposed via
drupalorg-api.Note that this might be useful for project_browser as well.
Comment #3
fjgarlin commentedI tried creating a view, which works, but
jsonapi_viewsmodule does not expose it because the view is not based on an entity type. I used this module https://www.drupal.org/project/view_custom_table, but in this case, it’sjsonapi_viewsthe one lacking what we need.I’m going to try the custom
drupalorg-api way.Comment #5
fjgarlin commentedMR needs review.
Endpoint is:
/drupalorg-api/project-maintainers?nid=123&uid=456The possible outcomes are:
- If nid and uid are passed: is_maintaner flag is returned
- If nid is passed: array with user ids and usernames returned
- If uid is passed: array with project ids and machine names returned
- If neither nid nor uid are passed: error
- If nid or uid are passed and are not valid ids: error
A "success" flag is always returned to determine if there is valid data or not.
Comment #6
andileco commentedThank you for working on this right away, @flgarlin! I am logged in on drupal.org, but when I navigate to:
https://www.drupal.org/drupalorg-api/project-maintainers?uid=2054544
I get a page not found. Do I need to try at a dev or test URL of D.O?
Comment #7
fjgarlin commentedIt’s not deployed to any environment yet. I marked it as "need review" to validate the approach and review the code.
Usually @drumm helps with that, but feel free to look at the code and give feedback if needed.
Once it’s deployed, I will provide links to fully test it.
Comment #8
podarokLet's depploy this, it'll help automate a lot of manual tasks
Comment #9
drummI don’t think we need this upfront, but we should make sure there’s enough surface area to add information about the types of maintainership (as in write to VCS / edit project / etc) without making breaking API changes or adding more parameters and extra complexity.
For example, “If nid is passed: array with user ids and usernames returned” might want another layer to the array to have space for the type of maintainership.
I think we can simplify a bit. Do we need:
We do have an old API for this in D7: https://www.drupal.org/project/3060/maintainers.json / https://www.drupal.org/project/token/maintainers.json We don’t need to provide API compatibility here, although it couldn’t hurt. Drupal.org’s use case of providing the maintainers to sync to security.drupal.org is no longer relevant. I’m not sure how much community use it gets.
GitLab also already has an API for this: https://docs.gitlab.com/api/projects/#list-a-users-projects
Comment #10
fjgarlin commentedI thought about providing more information about the level of maintainership, but wasn't sure about it, so I kept it as simple as possible for this implementation to precisely discuss these type of things.
> Do we need logic for handling when both nid & uid are provided?
That could be achieved by providing just one param and reading the result. I saw it as a quick 1/0 but yeah, it could actually lead to making more unnecessary calls. I'll remove the logic for "both" params.
> Do we need usernames when getting the list of maintainers?
Getting only user IDs might lead to additional calls to get the usernames. I thought that username is probably the one thing that most people will be interested in. eg: Project Browser might want this and will render links to the users. User ID and username should be enough to build things. I'll keep up unless you ask me to remove it after sharing this possible use case.
> Do we need project names when getting the list of projects maintained?
Same logic applies here. A list of project IDs might be insufficient and lead to extra calls. ID and project name gives enough information to at least render a list of links.
I wasn't aware of that old api! That's a good reference.
Action points:
- Remove logic for both nid and uid params together
- Expand output to include level of maintainership
Comment #11
fjgarlin commentedFeedback addressed.
Case 1:
/drupalorg-api/project-maintainers?nid=3060Case 2:
/drupalorg-api/project-maintainers?uid=3064Case 3: Wrong params or IDs
Comment #12
drummpodarok / andileco - does the current draft of the API responses fulfill your needs? How specifically are you planning to use the API?
Since API design is relatively permanent, now is our chance to get something that works long-term. We don’t need to rush to deploy something only to find something we want to change.
Since those are made by pathauto, the user profile links are not exactly the username; spaces/punctuation/etc are altered.
Comment #13
andileco commentedHi @drumm, there's a video of what I ultimately want to use this for in this Slack thread: https://drupal.slack.com/archives/C51GNJG91/p1764246715745809?thread_ts=...
(I want to enter my username in a field and get a table of all the projects I'm listed in a maintainer of). Case #2 would satisfy my needs.
Comment #14
fjgarlin commentedYup, my thinking would be that links would be
https://www.drupal.org/user/UIDand the text of the link would be the username. Username can change, UID won't.Comment #15
podarokUse cases @drumm
Given, I'm maintainer of multiple modules at drupal.org
I'm using dorgcli cli tool and JSON:API + custom REST drupal.org API to maintain modules with
- mass updating module's page description ( node body )
- mass changing permissions for users in maintainers ( add/remove user to/from 130+ projects )
- mass changing projects' taxonomy
- mass viewing all RTBC/needs work/critical issues ( at some point to be replaced by GitLab, I assume )
- mass path to MR conversion for issues with patches
- mass MR merge, tag ( these are on GitHub only, all good ) , release ( on drupal.org )
Comment #19
fjgarlin commentedRebased with latest changes. New MR, same code changes.
Comment #20
fjgarlin commentedPer conversation in stand up with @drumm, this is RTBC and can be merged.
Comment #22
fjgarlin commentedThis is now deployed.
- Project maintainers: https://www.drupal.org/drupalorg-api/project-maintainers?nid=3060
- Project maintained by a user: https://www.drupal.org/drupalorg-api/project-maintainers?uid=2054544 (example from #6)