* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * reformat all the things (prettier 3) * update tests to await calls to prettier.format() --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: chris48s <git@chris-shaw.dev>
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
import { BaseJsonService } from '../index.js'
|
|
|
|
export default class GitLabBase extends BaseJsonService {
|
|
static auth = {
|
|
passKey: 'gitlab_token',
|
|
serviceKey: 'gitlab',
|
|
}
|
|
|
|
async fetch({ url, options, schema, httpErrors }) {
|
|
return this._requestJson(
|
|
this.authHelper.withBearerAuthHeader({
|
|
schema,
|
|
url,
|
|
options,
|
|
httpErrors,
|
|
}),
|
|
)
|
|
}
|
|
|
|
async fetchPage({ page, requestParams, schema }) {
|
|
const { res, buffer } = await this._request(
|
|
this.authHelper.withBearerAuthHeader({
|
|
...requestParams,
|
|
...{ options: { searchParams: { page } } },
|
|
}),
|
|
)
|
|
|
|
const json = this._parseJson(buffer)
|
|
const data = this.constructor._validate(json, schema)
|
|
return { res, data }
|
|
}
|
|
|
|
async fetchPaginatedArrayData({
|
|
url,
|
|
options,
|
|
schema,
|
|
httpErrors,
|
|
firstPageOnly = false,
|
|
}) {
|
|
const requestParams = {
|
|
url,
|
|
options: {
|
|
headers: { Accept: 'application/json' },
|
|
searchParams: { per_page: 100 },
|
|
...options,
|
|
},
|
|
httpErrors,
|
|
}
|
|
|
|
const {
|
|
res: { headers },
|
|
data,
|
|
} = await this.fetchPage({ page: 1, requestParams, schema })
|
|
const numberOfPages = headers['x-total-pages']
|
|
|
|
if (numberOfPages === 1 || firstPageOnly) {
|
|
return data
|
|
}
|
|
|
|
const pageData = await Promise.all(
|
|
[...Array(numberOfPages - 1).keys()].map((_, i) =>
|
|
this.fetchPage({ page: ++i + 1, requestParams, schema }),
|
|
),
|
|
)
|
|
return [...data].concat(...pageData)
|
|
}
|
|
}
|