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

Add [GitlabPipeline] badge #2325

Merged
merged 8 commits into from
Nov 18, 2018
Merged

Add [GitlabPipeline] badge #2325

merged 8 commits into from
Nov 18, 2018

Conversation

paulmelnikow
Copy link
Member

There's a lot of demand for the Gitlab badges (#541) and the PR has been lingering, so I thought I'd start off one of the simple ones as a new-style service. This one is SVG-based, so it shouldn't require the API-token logic which could use some more testing and will require us to create an app and configure it on our server.

We don't have any validation in place for queryParams. Probably this should be added to BaseService, though for the time being I extracted a helper function.

Thanks to @LVMBDV for getting this work started in #1838!

@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Nov 15, 2018
@shields-ci
Copy link

shields-ci commented Nov 15, 2018

Messages
📖 ✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2325 November 15, 2018 16:35 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2325 November 15, 2018 16:57 Inactive
@paulmelnikow paulmelnikow added the blocker PRs and epics which block other work label Nov 15, 2018
@paulmelnikow
Copy link
Member Author

Have labeled this a blocker, as I won't prioritize the work of continuing to rewrite #1838 until this is merged.

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2325 November 17, 2018 15:29 Inactive
const queryParamsSchema = Joi.object({
// TODO This accepts URLs with query strings and fragments, which should be
// rejected.
gitlab_url: Joi.string().uri({ scheme: ['https'] }),
Copy link
Member

Choose a reason for hiding this comment

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

In this case, maybe it would be easier to validate and then work out if we've got a queryString (or strip it away) by parsing into a URLObject instead of using Joi:

> const { URL } = require('url')
> const url = new URL('http://foo.bar/baz?foo=bar')
> url
URL {
  href: 'http://foo.bar/baz?foo=bar',
  origin: 'http://foo.bar',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'foo.bar',
  hostname: 'foo.bar',
  port: '',
  pathname: '/baz',
  search: '?foo=bar',
  searchParams: URLSearchParams { 'foo' => 'bar' },
  hash: '' }

Copy link
Member Author

Choose a reason for hiding this comment

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

That could work… though it's a somewhat messy thing to replicate across other services that might use this. Adding some flags to the Joi function seems like a better way to handle it.

Checking for valid URLs is a good start. It doesn't feel important to get this perfect.

services/gitlab/gitlab-pipeline-status.service.js Outdated Show resolved Hide resolved
services/gitlab/gitlab-pipeline-status.service.js Outdated Show resolved Hide resolved
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2325 November 17, 2018 19:46 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2325 November 17, 2018 20:14 Inactive
// hosted gitlab.
query: { gitlab_url: 'https://gitlab.com' },
namedParams: { user: 'GNOME', repo: 'pango' },
query: { gitlab_url: 'https://gitlab.gnome.org' },
Copy link
Member

Choose a reason for hiding this comment

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

It might not be directly related to the changes in this PR (I suspect it was introduced in #2308 ), but I noticed that the query gets passed through to the placeholder example but not the one with the params filled in:

screenshot at 2018-11-18 12-46-46

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. I noticed that too: #2339

Copy link
Member

Choose a reason for hiding this comment

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

one step ahead 👟

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is approved why don't we merge this. It'll make #2339 easier to review. I probably should have just added that change here.

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

I think this is fine.. I wonder why the service tests haven't completed cleanly?

@paulmelnikow
Copy link
Member Author

Yea… they did run, though in #2326 they got new names so I changed the branch protection config, and now GitHub is waiting for the new names. Merging should fix it.

screen shot 2018-11-18 at 9 59 56 am

@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

@paulmelnikow paulmelnikow deleted the gitlab branch November 18, 2018 15:06
paulmelnikow added a commit that referenced this pull request Dec 6, 2018
This starts the rewrite of the dynamic badges. I've pulled into BaseService an initial version of the query param validation from #2325.

I've extended from BaseJsonService to avoid duplicating the deserialization logic, though it means there is a bit of duplicated code among the three dynamic services. The way to unravel this would be to move the logic from `_requestJson` and friends from the base classes into functions so DynamicJson can inherit from BaseDynamic. Would that be worth it?

This introduces a regression of #1446 for this badge.

Close #2345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker PRs and epics which block other work service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants