Skip to content
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

Support nested GitLab subgroups for pipeline badge #6427

Closed
1 of 3 tasks
ProfessorManhattan opened this issue Apr 30, 2021 · 8 comments · Fixed by #7159
Closed
1 of 3 tasks

Support nested GitLab subgroups for pipeline badge #6427

ProfessorManhattan opened this issue Apr 30, 2021 · 8 comments · Fixed by #7159
Labels
bug Bugs in badges and the frontend service-badge Accepted and actionable changes, features, and bugs

Comments

@ProfessorManhattan
Copy link

ProfessorManhattan commented Apr 30, 2021

Are you experiencing an issue with...

🪲 Description

For the GitLab pipeline status, shields.io does not seem to support subgroups. Some of my repositories are in multiple levels of subgroups.

🔗 Link to the badge

https://img.shields.io/gitlab/pipeline/megabyte-labs/dockerfile/ci-pipeline/ansible-lint/master?style=for-the-badge

And here is the URL I'm trying to make a badge for:

https://gitlab.com/megabyte-labs/dockerfile/ci-pipeline/ansible-lint

@ProfessorManhattan ProfessorManhattan added the question Support questions, usage questions, unconfirmed bugs, discussions, ideas label Apr 30, 2021
@chris48s
Copy link
Member

chris48s commented May 5, 2021

Hi thanks for raising this. The issue here is that we're reading this as

  • user/repo: megabyte-labs/dockerfile
  • branch: ci-pipeline/ansible-lint/master

whereas really it is

  • user/repo: megabyte-labs/dockerfile/ci-pipeline/ansible-lint
  • branch: master

I'm don't think we could fix this with the current URL schema given we need to split the branch name off from the user/repo to make the upstream call but both the user/repo and branch name can both contain an arbitrary number of slashes - we don't know where to make the cut. I think we'd have to move it to a new route and set up a redirect for legacy users that makes the current assumption.

@chris48s chris48s added bug Bugs in badges and the frontend service-badge Accepted and actionable changes, features, and bugs and removed question Support questions, usage questions, unconfirmed bugs, discussions, ideas labels May 5, 2021
@ProfessorManhattan
Copy link
Author

ProfessorManhattan commented May 5, 2021 via email

@chris48s
Copy link
Member

chris48s commented May 8, 2021

I think the way to do it would be to take the existing route

static route = {
base: 'gitlab/pipeline',
pattern: ':user/:repo/:branch+',
queryParamSchema,
}
and

Convert branch to a queryParam

const queryParamSchema = Joi.object({
gitlab_url: optionalUrl,
}).required()

Merge user/repo into a single :userRepo+ param (which can just be passed upstream as a block). We can only have one param with a slash in it and it has to be the last one
Move the base to something like gitlab/pipelines or gitlab/pipeline-status
Update the code/examples/tests for the new routes
Create another redirector route like
const GitlabPipelineStatusRedirector = redirector({
category: 'build',
route: {
base: 'gitlab/pipeline',
pattern: ':user/:repo',
},
transformPath: ({ user, repo }) => `/gitlab/pipeline/${user}/${repo}/master`,
dateAdded: new Date('2020-07-12'),
})
to redirect existing calls to the old route (retaining the assumption that only branch can have slashes in it so we don't break existing badge URLs

Annoyingly, the gitlab coverage badge is going to have the same issue that needs fixing using the same process.
This one is super-annoying because all of our coverage badges are /something/coverage and I can't really think of a good name to move this to. Maybe code-coverage?

@calebcartwright
Copy link
Member

I think the way to do it would be to take the existing route

Agreed, that sounds like a good approach and one I believe we've taken in similar situations previously

Move the base to something like gitlab/pipelines or gitlab/pipeline-status

I'd vote for pipeline-status, seems like it'd align well with other routes

This one is super-annoying because all of our coverage badges are /something/coverage and I can't really think of a good name to move this to. Maybe code-coverage

nuts. that is a challenging one. i think code-coverage will work fine, and maybe we even consider adding an inline comment on the route to the effect of "don't copy this particular route pattern" since this is more of an exception than the rule/standard operating procedure

@paulmelnikow paulmelnikow changed the title Cannot Access Public GitLab Pipeline Status When In Nested Subgroups Support nested GitLab subgroups for pipeline badge Jul 9, 2021
@Kage-Yami
Copy link

I'm guessing this issue also applies to other badges... I think I'm experiencing the same issue with the "Lines of Code" badge - of course, I don't know if the shortcoming is part of Shields.io, or Tokei[.rs] (also not sure if Shields.io self-hosts the library or not).

The example repository is here: https://gitlab.com/isekai/train-valley-2-modding/AutoHideCompletedLevels

... as I was writing this, I realised that there doesn't seem to be a way to specify the branch for Lines of Code... so that might be the actual problem (I have no idea); my only branches are main and develop. So if that's the issue, then I'll look at creating a separate ticket for Lines of Code branches.

For both the Pipeline Status and Lines of Code badges, I tried a couple of different options for the project path; some result in the SVG being generated successfully, but with no data, others fail to generate the SVG entirely (%252F being what the wizard generated if I entered a literal %2F in an attempt to pre-encode the slash, similar to what is required for GitLab's APIs):

image

@chris48s
Copy link
Member

chris48s commented Oct 4, 2021

With Tokei, the situation is different:

  1. The upstream doesn't support this either https://tokei.rs/b1/gitlab/isekai/train-valley-2-modding/AutoHideCompletedLevels is a 404 so I think that's an issue for the upstream.
  2. If the upstream service did support it, we could enable this by changing our route from :provider/:user/:repo to :provider/:user/:repo+ because there's no branch param in the route for tokei.

GitLab pipelines is a unique problem here because there are two route params that could possibly have a slash in them.

@ProfessorManhattan
Copy link
Author

There are also repo IDs provided on each repository page on GitLab

@calebcartwright
Copy link
Member

There may actually be some additional layers of complexity here.

We currently retrieve the pipeline status by scraping GitLab's own pipeline status badge. This works fine with a project path, but does not seem to honor the project id:

https://gitlab.com/gitlab-org/gitlab
project path works - https://gitlab.com/gitlab-org/gitlab/badges/master/pipeline.svg

project id does not - https://gitlab.com/278964/badges/master/pipeline.svg

As such I think that so long as we're utilizing GitLab's status badges, using the id is not a viable option.

Switching from scraping the upstream svg's to utilizing the Pipeline API might be tricky too, as the API only really supports a listing of all pipelines or requires the numeric pipeline id to be provided as a route parameter in order to get the status for a specific pipeline. Perhaps it'd be possible for us to continue to have a required ref in our route so we could potentially use with a combination of other upstream params to find the "right" pipeline via either of those upstream endpoints, but that seems like it has a lot more challenges to solve.

I agree with Chris that the best course of action tactically, and perhaps even strategically, is for us to switch over to an updated route with a corresponding redirector to prevent breaking existing badges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs in badges and the frontend service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants