-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GitHubChecksStatus] Add commit check badge (#5973)
* Add GH commit check badge * Fix class name, tests * Run prettier * Refactor to generic checks * Run prettier * Make keywords separate from title * Make commit failing tests actually fail * Resolve suggested edits * Sanitize imports * Follow import order requirements Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d0b93b4
commit d69f7b6
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const { isBuildStatus, renderBuildStatusBadge } = require('../build-status') | ||
const { GithubAuthV3Service } = require('./github-auth-service') | ||
const { documentation, errorMessagesFor } = require('./github-helpers') | ||
|
||
const schema = Joi.object({ | ||
state: isBuildStatus, | ||
}).required() | ||
|
||
module.exports = class GithubChecksStatus extends GithubAuthV3Service { | ||
static category = 'build' | ||
static route = { | ||
base: 'github/checks-status', | ||
pattern: ':user/:repo/:ref', | ||
} | ||
|
||
static examples = [ | ||
{ | ||
title: 'GitHub branch checks state', | ||
namedParams: { | ||
user: 'badges', | ||
repo: 'shields', | ||
ref: 'master', | ||
}, | ||
staticPreview: renderBuildStatusBadge({ | ||
status: 'success', | ||
}), | ||
keywords: ['status'], | ||
documentation, | ||
}, | ||
{ | ||
title: 'GitHub commit checks state', | ||
namedParams: { | ||
user: 'badges', | ||
repo: 'shields', | ||
ref: '91b108d4b7359b2f8794a4614c11cb1157dc9fff', | ||
}, | ||
staticPreview: renderBuildStatusBadge({ | ||
status: 'success', | ||
}), | ||
keywords: ['status'], | ||
documentation, | ||
}, | ||
{ | ||
title: 'GitHub tag checks state', | ||
namedParams: { | ||
user: 'badges', | ||
repo: 'shields', | ||
ref: '3.3.0', | ||
}, | ||
staticPreview: renderBuildStatusBadge({ | ||
status: 'success', | ||
}), | ||
keywords: ['status'], | ||
documentation, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { label: 'checks' } | ||
|
||
async handle({ user, repo, ref }) { | ||
const { state } = await this._requestJson({ | ||
url: `/repos/${user}/${repo}/commits/${ref}/status`, | ||
errorMessages: errorMessagesFor('ref or repo not found'), | ||
schema, | ||
}) | ||
|
||
return renderBuildStatusBadge({ status: state }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const t = (module.exports = require('../tester').createServiceTester()) | ||
const { isBuildStatus } = require('../build-status') | ||
|
||
t.create('branch checks (branch)') | ||
.get('/badges/shields/master.json') | ||
.expectBadge({ | ||
label: 'checks', | ||
message: isBuildStatus, | ||
}) | ||
|
||
t.create('checks - nonexistent ref') | ||
.get('/badges/shields/this-ref-does-not-exist.json') | ||
.expectBadge({ | ||
label: 'checks', | ||
message: 'ref or repo not found', | ||
color: 'red', | ||
}) |