-
-
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.
- Loading branch information
1 parent
6f2c0a2
commit 586edc1
Showing
1 changed file
with
52 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,52 @@ | ||
import fs from 'fs' | ||
import Joi from 'joi' | ||
import { nonNegativeInteger } from '../validators.js' | ||
import { GithubAuthV3Service } from './github-auth-service.js' | ||
import { documentation, httpErrorsFor } from './github-helpers.js' | ||
|
||
const schema = Joi.object({ | ||
followers: nonNegativeInteger, | ||
}).required() | ||
|
||
export default class GithubIssue7929Service 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: 'Follow', | ||
style: 'social', | ||
}), | ||
queryParams: { label: 'Follow' }, | ||
documentation, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { label: 'latest@', namedLogo: 'github' } | ||
|
||
static render({ releases }) { | ||
return { | ||
message: releases?.length, | ||
color: 'blue', | ||
} | ||
} | ||
|
||
async handle({ user, repo, branch }) { | ||
const releases = await this._requestJson({ | ||
url: `/repos/${user}/${repo}/releases?per_page=50`, | ||
schema, | ||
httpErrors: httpErrorsFor('user not found'), | ||
}) | ||
|
||
fs.writeFileSync('./test.json', releases) | ||
|
||
console.log(releases) | ||
|
||
return this.constructor.render({ releases }) | ||
} | ||
} |