-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[GitHub] add latest release of a branch badge #9661
Closed
karolwydmuch
wants to merge
2
commits into
badges:master
from
karolwydmuch:issue-7929-latest-version-specific-branch
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,69 @@ | ||
import Joi from 'joi' | ||
import { GithubAuthV3Service } from './github-auth-service.js' | ||
import { documentation, httpErrorsFor } from './github-helpers.js' | ||
|
||
const MAXIMUM_SEARCHING_PAGE_NUMBER = 5 | ||
|
||
const schema = Joi.array().items( | ||
Joi.object({ | ||
target_commitish: Joi.string(), | ||
tag_name: Joi.string(), | ||
}), | ||
) | ||
|
||
export default class GithubLatestBranchRelease extends GithubAuthV3Service { | ||
static category = 'version' | ||
static route = { | ||
base: 'github/v/latest-branch-release', | ||
pattern: ':user/:repo/:branch', | ||
} | ||
|
||
static examples = [ | ||
{ | ||
title: 'GitHub latest branch release', | ||
namedParams: { user: 'laravel', repo: 'framework', branch: '10.x' }, | ||
staticPreview: Object.assign(this.render({ releases: [] }), { | ||
label: 'latest-release@10.x', | ||
message: 'v10.28.0', | ||
style: 'social', | ||
}), | ||
queryParams: {}, | ||
documentation, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { namedLogo: 'github' } | ||
|
||
static render({ branch, latestBranchTag }) { | ||
return { | ||
label: `latest-release@${branch}`, | ||
message: latestBranchTag || '', | ||
color: 'blue', | ||
} | ||
} | ||
|
||
async handle({ user, repo, branch }) { | ||
let shouldRetry = true | ||
let currentPage = 0 | ||
let latestBranchTag | ||
|
||
while (shouldRetry && currentPage < MAXIMUM_SEARCHING_PAGE_NUMBER) { | ||
currentPage++ | ||
const releases = await this._requestJson({ | ||
url: `/repos/${user}/${repo}/releases?per_page=100&page=${currentPage}`, | ||
schema, | ||
httpErrors: httpErrorsFor('user not found'), | ||
}) | ||
|
||
latestBranchTag = releases.filter( | ||
release => release.target_commitish === branch, | ||
)[0]?.tag_name | ||
|
||
if (latestBranchTag) { | ||
shouldRetry = false | ||
} | ||
} | ||
|
||
return this.constructor.render({ branch, latestBranchTag }) | ||
} | ||
} |
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,33 @@ | ||
import Joi from 'joi' | ||
import { isSemver } from '../test-validators.js' | ||
import { ServiceTester } from '../tester.js' | ||
|
||
export const t = new ServiceTester({ | ||
id: 'GithubLatestBranchRelease', | ||
title: 'Github Latest Branch Release', | ||
pathPrefix: '/github', | ||
}) | ||
|
||
t.create('Release') | ||
.get('/v/release/expressjs/express.json') | ||
.expectBadge({ label: 'release', message: isSemver, color: 'blue' }) | ||
|
||
t.create('Prerelease') | ||
.get('/v/release/expressjs/express.json?include_prereleases') | ||
.expectBadge({ | ||
label: 'release', | ||
message: isSemver, | ||
color: Joi.string().allow('blue', 'orange').required(), | ||
}) | ||
|
||
t.create('Latest release (release)') | ||
.get('/v/release/expressjs/express.json?display_name=release') | ||
.expectBadge({ label: 'release', message: isSemver, color: 'blue' }) | ||
|
||
t.create('Release (No releases)') | ||
.get('/v/release/badges/daily-tests.json') | ||
.expectBadge({ label: 'release', message: 'no releases or repo not found' }) | ||
|
||
t.create('Release (repo not found)') | ||
.get('/v/release/badges/helmets.json') | ||
.expectBadge({ label: 'release', message: 'no releases or repo not found' }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up coming back to this, none of the tests in this file are actually testing the service class that has been added in this PR, but lets not get bogged down in that for the moment