Skip to content

Commit

Permalink
migrate examples to openApi part 37; affects [bitbucket bitrise chrom…
Browse files Browse the repository at this point in the history
…ewebstore circleci] (#9881)

* migrate some services from examples to openApi

* Fix Bitbucket tests and examples

* Fix CircleCI and Bitrise tests

* Use fake token in Bitrise examples

* Use JohnEstropia/CoreStore token in Bitrise tests
  • Loading branch information
PyvesB authored Feb 14, 2024
1 parent c121889 commit cb2ebe2
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 104 deletions.
31 changes: 21 additions & 10 deletions services/bitbucket/bitbucket-issues.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const bitbucketIssuesSchema = Joi.object({
size: nonNegativeInteger,
Expand All @@ -10,22 +10,33 @@ const bitbucketIssuesSchema = Joi.object({
function issueClassGenerator(raw) {
const routePrefix = raw ? 'issues-raw' : 'issues'
const badgeSuffix = raw ? '' : ' open'
const titleSuffix = raw ? ' (raw)' : ''

return class BitbucketIssues extends BaseJsonService {
static name = `BitbucketIssues${raw ? 'Raw' : ''}`
static category = 'issue-tracking'
static route = { base: `bitbucket/${routePrefix}`, pattern: ':user/:repo' }

static examples = [
{
title: 'Bitbucket open issues',
namedParams: {
user: 'atlassian',
repo: 'python-bitbucket',
static get openApi() {
const key = `/bitbucket/${routePrefix}/{user}/{repo}`
const route = {}
route[key] = {
get: {
summary: `Bitbucket open issues ${titleSuffix}`,
parameters: pathParams(
{
name: 'user',
example: 'shields-io',
},
{
name: 'repo',
example: 'test-repo',
},
),
},
staticPreview: this.render({ issues: 33 }),
},
]
}
return route
}

static defaultBadgeData = { label: 'issues' }

Expand Down
8 changes: 4 additions & 4 deletions services/bitbucket/bitbucket-issues.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ export const t = new ServiceTester({
})

t.create('issues-raw (valid)')
.get('/issues-raw/atlassian/python-bitbucket.json')
.get('/issues-raw/shields-io/test-repo.json')
.expectBadge({
label: 'issues',
message: isMetric,
})

t.create('issues-raw (not found)')
.get('/issues-raw/atlassian/not-a-repo.json')
.get('/issues-raw/shields-io/not-a-repo.json')
.expectBadge({ label: 'issues', message: 'not found' })

t.create('issues-raw (private repo)')
.get('/issues-raw/chris48s/example-private-repo.json')
.expectBadge({ label: 'issues', message: 'private repo' })

t.create('issues (valid)')
.get('/issues/atlassian/python-bitbucket.json')
.get('/issues/shields-io/test-repo.json')
.expectBadge({
label: 'issues',
message: isMetricOpenIssues,
})

t.create('issues (not found)')
.get('/issues/atlassian/not-a-repo.json')
.get('/issues/shields-io/not-a-repo.json')
.expectBadge({ label: 'issues', message: 'not found' })

t.create('issues (private repo)')
Expand Down
6 changes: 3 additions & 3 deletions services/bitbucket/bitbucket-pipelines.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class BitbucketPipelines extends BaseJsonService {
parameters: pathParams(
{
name: 'user',
example: 'atlassian',
example: 'shields-io',
},
{
name: 'repo',
example: 'adf-builder-javascript',
example: 'test-repo',
},
{
name: 'branch',
example: 'task/SECO-2168',
example: 'main',
},
),
},
Expand Down
28 changes: 13 additions & 15 deletions services/bitbucket/bitbucket-pipelines.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ function bitbucketApiResponse(status) {
})
}

t.create('master build result (not found)')
.get('/atlassian/not-a-repo/master.json')
t.create('main build result (not found)')
.get('/shields-io/not-a-repo/main.json')
.expectBadge({ label: 'build', message: 'not found' })

t.create('branch build result (valid)')
.get('/atlassian/adf-builder-javascript/shields-test-dont-remove.json')
.get('/shields-io/test-repo/main.json')
.expectBadge({
label: 'build',
message: isBuildStatus,
})

t.create('branch build result (not found)')
.get('/atlassian/not-a-repo/some-branch.json')
.get('/shields-io/not-a-repo/some-branch.json')
.expectBadge({ label: 'build', message: 'not found' })

t.create('branch build result (never built)')
.get('/atlassian/adf-builder-javascript/some/new/branch.json')
.get('/shields-io/test-repo/P-Y/update-readme-1704629121998.json')
.expectBadge({ label: 'build', message: 'never built' })

t.create('build result (passing)')
.get('/atlassian/adf-builder-javascript/master.json')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
Expand All @@ -52,7 +52,7 @@ t.create('build result (passing)')
.expectBadge({ label: 'build', message: 'passing' })

t.create('build result (failing)')
.get('/atlassian/adf-builder-javascript/master.json')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
Expand All @@ -61,7 +61,7 @@ t.create('build result (failing)')
.expectBadge({ label: 'build', message: 'failing' })

t.create('build result (error)')
.get('/atlassian/adf-builder-javascript/master.json')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
Expand All @@ -70,7 +70,7 @@ t.create('build result (error)')
.expectBadge({ label: 'build', message: 'error' })

t.create('build result (stopped)')
.get('/atlassian/adf-builder-javascript/master.json')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
Expand All @@ -79,7 +79,7 @@ t.create('build result (stopped)')
.expectBadge({ label: 'build', message: 'stopped' })

t.create('build result (expired)')
.get('/atlassian/adf-builder-javascript/master.json')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
Expand All @@ -88,7 +88,7 @@ t.create('build result (expired)')
.expectBadge({ label: 'build', message: 'expired' })

t.create('build result (unexpected status)')
.get('/atlassian/adf-builder-javascript/master.json')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
Expand All @@ -97,7 +97,5 @@ t.create('build result (unexpected status)')
.expectBadge({ label: 'build', message: 'invalid response data' })

t.create('build result no branch redirect')
.get('/atlassian/adf-builder-javascript.svg')
.expectRedirect(
'/bitbucket/pipelines/atlassian/adf-builder-javascript/master.svg',
)
.get('/shields-io/test-repo.svg')
.expectRedirect('/bitbucket/pipelines/shields-io/test-repo/master.svg')
46 changes: 27 additions & 19 deletions services/bitbucket/bitbucket-pull-request.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Joi from 'joi'
import { AuthHelper } from '../../core/base-service/auth-helper.js'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger, optionalUrl } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParam, queryParam } from '../index.js'

const schema = Joi.object({
size: nonNegativeInteger,
Expand All @@ -21,6 +21,7 @@ const httpErrors = {
function pullRequestClassGenerator(raw) {
const routePrefix = raw ? 'pr-raw' : 'pr'
const badgeSuffix = raw ? '' : ' open'
const titleSuffix = raw ? ' (raw)' : ''

return class BitbucketPullRequest extends BaseJsonService {
static name = `BitbucketPullRequest${raw ? 'Raw' : ''}`
Expand All @@ -31,25 +32,32 @@ function pullRequestClassGenerator(raw) {
queryParamSchema,
}

static examples = [
{
title: 'Bitbucket open pull requests',
namedParams: {
user: 'atlassian',
repo: 'python-bitbucket',
static get openApi() {
const key = `/bitbucket/${routePrefix}/{user}/{repo}`
const route = {}
route[key] = {
get: {
summary: `Bitbucket open pull requests ${titleSuffix}`,
parameters: [
pathParam({
name: 'user',
example: 'shields-io',
}),
pathParam({
name: 'repo',
example: 'test-repo',
}),
queryParam({
name: 'server',
example: 'https://bitbucket.mydomain.net',
description:
'When not specified, this will default to `https://bitbucket.org`.',
}),
],
},
staticPreview: this.render({ prs: 22 }),
},
{
title: 'Bitbucket Server open pull requests',
namedParams: {
user: 'foo',
repo: 'bar',
},
queryParams: { server: 'https://bitbucket.mydomain.net' },
staticPreview: this.render({ prs: 42 }),
},
]
}
return route
}

static defaultBadgeData = { label: 'pull requests' }

Expand Down
2 changes: 1 addition & 1 deletion services/bitbucket/bitbucket-pull-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('BitbucketPullRequest', function () {
},
private: { bitbucket_username: user, bitbucket_password: pass },
},
{ user: 'atlassian', repo: 'python-bitbucket' },
{ user: 'shields-io', repo: 'test-repo' },
),
).to.deep.equal({
message: '42',
Expand Down
8 changes: 4 additions & 4 deletions services/bitbucket/bitbucket-pull-request.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ export const t = new ServiceTester({
})

t.create('pr-raw (valid)')
.get('/pr-raw/atlassian/python-bitbucket.json')
.get('/pr-raw/shields-io/test-repo.json')
.expectBadge({
label: 'pull requests',
message: isMetric,
})

t.create('pr-raw (not found)')
.get('/pr-raw/atlassian/not-a-repo.json')
.get('/pr-raw/shields-io/not-a-repo.json')
.expectBadge({ label: 'pull requests', message: 'not found' })

t.create('pr-raw (private repo)')
.get('/pr-raw/chris48s/example-private-repo.json')
.expectBadge({ label: 'pull requests', message: 'not found' })

t.create('pr (valid)').get('/pr/atlassian/python-bitbucket.json').expectBadge({
t.create('pr (valid)').get('/pr/shields-io/test-repo.json').expectBadge({
label: 'pull requests',
message: isMetricOpenIssues,
})

t.create('pr (not found)')
.get('/pr/atlassian/not-a-repo.json')
.get('/pr/shields-io/not-a-repo.json')
.expectBadge({ label: 'pull requests', message: 'not found' })

t.create('pr (private repo)')
Expand Down
46 changes: 38 additions & 8 deletions services/bitrise/bitrise.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParam, queryParam } from '../index.js'

// https://devcenter.bitrise.io/api/app-status-badge/
const schema = Joi.object({
Expand All @@ -18,14 +18,44 @@ export default class Bitrise extends BaseJsonService {
queryParamSchema,
}

static examples = [
{
title: 'Bitrise',
namedParams: { appId: '3ff11fe8457bd304', branch: 'master' },
queryParams: { token: 'lESRN9rEFFfDq92JtXs_jw' },
staticPreview: this.render({ status: 'success' }),
static openApi = {
'/bitrise/{appId}': {
get: {
summary: 'Bitrise',
parameters: [
pathParam({
name: 'appId',
example: '4a2b10a819d12b67',
}),
queryParam({
name: 'token',
example: 'abc123def456',
required: true,
}),
],
},
},
'/bitrise/{appId}/{branch}': {
get: {
summary: 'Bitrise (branch)',
parameters: [
pathParam({
name: 'appId',
example: 'e736852157296019',
}),
pathParam({
name: 'branch',
example: 'master',
}),
queryParam({
name: 'token',
example: 'abc123def456',
required: true,
}),
],
},
},
]
}

static defaultBadgeData = { label: 'bitrise' }

Expand Down
10 changes: 5 additions & 5 deletions services/bitrise/bitrise.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('deploy status')
.get('/3ff11fe8457bd304.json?token=lESRN9rEFFfDq92JtXs_jw')
.get('/e736852157296019.json?token=vhgAmaiF3tWZoQyFLkKM7g')
.expectBadge({
label: 'bitrise',
message: isBuildStatus,
})

t.create('deploy status with branch')
.get('/3ff11fe8457bd304/master.json?token=lESRN9rEFFfDq92JtXs_jw')
.get('/e736852157296019/master.json?token=vhgAmaiF3tWZoQyFLkKM7g')
.expectBadge({
label: 'bitrise',
message: isBuildStatus,
})

t.create('unknown branch')
.get('/cde737473028420d/unknown.json?token=GCIdEzacE4GW32jLVrZb7A')
.get('/e736852157296019/unknown.json?token=vhgAmaiF3tWZoQyFLkKM7g')
.expectBadge({ label: 'bitrise', message: 'branch not found' })

t.create('invalid token')
.get('/cde737473028420d/unknown.json?token=token')
.get('/e736852157296019/unknown.json?token=token')
.expectBadge({ label: 'bitrise', message: 'app not found or invalid token' })

t.create('invalid App ID')
.get('/invalid/master.json?token=GCIdEzacE4GW32jLVrZb7A')
.get('/invalid/master.json?token=vhgAmaiF3tWZoQyFLkKM7g')
.expectBadge({ label: 'bitrise', message: 'app not found or invalid token' })
Loading

0 comments on commit cb2ebe2

Please sign in to comment.