Skip to content

Commit

Permalink
Merge branch 'master' into gitlabci-include
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 24, 2021
2 parents 2136973 + 4d349b4 commit cc81ca2
Show file tree
Hide file tree
Showing 29 changed files with 208 additions and 105 deletions.
2 changes: 1 addition & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ If you wish to change it to something else like "ci" then it will look like `"ci

If you are using a semantic prefix for your commits, then you will want to enable this setting.
Although it's configurable to a package-level, it makes most sense to configure it at a repository level.
If configured to `true`, then the `semanticCommitScope` and `semanticCommitType` fields will be used for each commit message and PR title.
If configured to `enabled`, then the `semanticCommitScope` and `semanticCommitType` fields will be used for each commit message and PR title.

However, please note that Renovate will autodetect if your repository is already using semantic commits or not and follow suit, so you only really need to configure this if you wish to _override_ Renovate's autodetected setting.

Expand Down
3 changes: 3 additions & 0 deletions lib/datasource/bitbucket-tags/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe(getName(__filename), () => {
httpMock.reset();
httpMock.setup();
});
afterEach(() => {
httpMock.reset();
});
describe('getReleases', () => {
it('returns tags from bitbucket cloud', async () => {
const body = {
Expand Down
6 changes: 6 additions & 0 deletions lib/datasource/github-tags/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ describe('datasource/github-tags', () => {
token: 'some-token',
});
});
afterEach(() => {
httpMock.reset();
});

describe('getDigest', () => {
const lookupName = 'some/dep';
Expand Down Expand Up @@ -114,6 +117,9 @@ describe('datasource/github-tags', () => {
token: 'some-token',
});
});
afterEach(() => {
httpMock.reset();
});

const depName = 'some/dep2';

Expand Down
3 changes: 3 additions & 0 deletions lib/datasource/gitlab-tags/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ describe('datasource/gitlab-tags', () => {
httpMock.reset();
httpMock.setup();
});
afterEach(() => {
httpMock.reset();
});
describe('getReleases', () => {
it('returns tags from custom registry', async () => {
const body = [
Expand Down
5 changes: 3 additions & 2 deletions lib/datasource/repology/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import * as packageCache from '../../util/cache/package';
import { Http } from '../../util/http';
import { getQueryString } from '../../util/url';
import { GetReleasesConfig, ReleaseResult } from '../common';

export const id = 'repology';
Expand Down Expand Up @@ -46,13 +47,13 @@ async function queryPackagesViaResolver(
packageName: string,
packageType: RepologyPackageType
): Promise<RepologyPackage[]> {
const query = new URLSearchParams({
const query = getQueryString({
repo: repoName,
name_type: packageType,
target_page: 'api_v1_project',
noautoresolve: 'on',
name: packageName,
}).toString();
});

// Retrieve list of packages by looking up Repology project
const packages = await queryPackages(
Expand Down
113 changes: 63 additions & 50 deletions lib/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,91 @@ import { ExtractConfig, PackageDependency, PackageFile } from '../common';
const isValidChartName = (name: string): boolean =>
!/[!@#$%^&*(),.?":{}/|<>A-Z]/.test(name);

interface Doc {
releases?: {
chart: string;
version: string;
}[];
repositories?: {
name: string;
url: string;
}[];
}

export function extractPackageFile(
content: string,
fileName: string,
config: ExtractConfig
): PackageFile {
let deps = [];
let doc;
let docs: Doc[];
const aliases: Record<string, string> = {};
try {
doc = yaml.safeLoad(content, { json: true });
docs = yaml.safeLoadAll(content, null, { json: true });
} catch (err) {
logger.debug({ err, fileName }, 'Failed to parse helmfile helmfile.yaml');
return null;
}
if (!(doc && is.array(doc.releases))) {
logger.debug({ fileName }, 'helmfile.yaml has no releases');
return null;
}
for (const doc of docs) {
if (!(doc && is.array(doc.releases))) {
logger.debug({ fileName }, 'helmfile.yaml has no releases');
return null;
}

if (doc.repositories) {
for (let i = 0; i < doc.repositories.length; i += 1) {
aliases[doc.repositories[i].name] = doc.repositories[i].url;
if (doc.repositories) {
for (let i = 0; i < doc.repositories.length; i += 1) {
aliases[doc.repositories[i].name] = doc.repositories[i].url;
}
}
}
logger.debug({ aliases }, 'repositories discovered.');
logger.debug({ aliases }, 'repositories discovered.');

deps = doc.releases.map((dep) => {
let depName = dep.chart;
let repoName = null;
deps = doc.releases.map((dep) => {
let depName = dep.chart;
let repoName = null;

// If starts with ./ is for sure a local path
if (dep.chart.startsWith('./')) {
return {
depName,
skipReason: 'local-chart',
} as PackageDependency;
}
// If starts with ./ is for sure a local path
if (dep.chart.startsWith('./')) {
return {
depName,
skipReason: 'local-chart',
} as PackageDependency;
}

if (dep.chart.includes('/')) {
const v = dep.chart.split('/');
repoName = v.shift();
depName = v.join('/');
} else {
repoName = dep.chart;
}
if (dep.chart.includes('/')) {
const v = dep.chart.split('/');
repoName = v.shift();
depName = v.join('/');
} else {
repoName = dep.chart;
}

const res: PackageDependency = {
depName,
currentValue: dep.version,
registryUrls: [aliases[repoName]]
.concat([config.aliases[repoName]])
.filter(Boolean),
};
const res: PackageDependency = {
depName,
currentValue: dep.version,
registryUrls: [aliases[repoName]]
.concat([config.aliases[repoName]])
.filter(Boolean),
};

// If version is null is probably a local chart
if (!res.currentValue) {
res.skipReason = SkipReason.LocalChart;
}
// If version is null is probably a local chart
if (!res.currentValue) {
res.skipReason = SkipReason.LocalChart;
}

// By definition on helm the chart name should be lowercase letter + number + -
// However helmfile support templating of that field
if (!isValidChartName(res.depName)) {
res.skipReason = SkipReason.UnsupportedChartType;
}
// By definition on helm the chart name should be lowercase letter + number + -
// However helmfile support templating of that field
if (!isValidChartName(res.depName)) {
res.skipReason = SkipReason.UnsupportedChartType;
}

// Skip in case we cannot locate the registry
if (is.emptyArray(res.registryUrls)) {
res.skipReason = SkipReason.UnknownRegistry;
}
// Skip in case we cannot locate the registry
if (is.emptyArray(res.registryUrls)) {
res.skipReason = SkipReason.UnknownRegistry;
}

return res;
});
return res;
});
}

return { deps, datasource: datasourceHelm.id } as PackageFile;
}
3 changes: 3 additions & 0 deletions lib/platform/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ describe(getName(__filename), () => {
password,
});
});
afterEach(() => {
httpMock.reset();
});

describe('initPlatform()', () => {
it('should throw if no endpoint', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import url, { URLSearchParams } from 'url';
import url from 'url';
import is from '@sindresorhus/is';
import delay from 'delay';
import type { PartialDeep } from 'type-fest';
Expand All @@ -21,7 +21,7 @@ import {
setBaseUrl,
} from '../../util/http/bitbucket-server';
import { sanitize } from '../../util/sanitize';
import { ensureTrailingSlash } from '../../util/url';
import { ensureTrailingSlash, getQueryString } from '../../util/url';
import {
BranchStatusConfig,
CreatePRConfig,
Expand Down Expand Up @@ -326,7 +326,7 @@ export async function getPrList(refreshCache?: boolean): Promise<Pr[]> {
searchParams['role.1'] = 'AUTHOR';
searchParams['username.1'] = config.username;
}
const query = new URLSearchParams(searchParams).toString();
const query = getQueryString(searchParams);
const values = await utils.accumulateValues(
`./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/pull-requests?${query}`
);
Expand Down
3 changes: 3 additions & 0 deletions lib/platform/bitbucket/comments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe(getName(__filename), () => {

setBaseUrl(baseUrl);
});
afterEach(() => {
httpMock.reset();
});

describe('ensureComment()', () => {
it('does not throw', async () => {
Expand Down
3 changes: 3 additions & 0 deletions lib/platform/bitbucket/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ describe('platform/bitbucket', () => {

setBaseUrl(baseUrl);
});
afterEach(() => {
httpMock.reset();
});

async function initRepoMock(
config?: Partial<RepoParams>,
Expand Down
1 change: 1 addition & 0 deletions lib/platform/bitbucket/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ describe('accumulateValues()', () => {
expect(res).toHaveLength(25);
expect(httpMock.getTrace()).toHaveLength(3);
expect(httpMock.getTrace()).toMatchSnapshot();
httpMock.reset();
});
});
3 changes: 3 additions & 0 deletions lib/platform/gitea/gitea-helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ describe('platform/gitea/gitea-helper', () => {
httpMock.setup();
setBaseUrl(baseUrl);
});
afterEach(() => {
httpMock.reset();
});

describe('getCurrentUser', () => {
it('should call /api/v1/user endpoint', async () => {
Expand Down
24 changes: 5 additions & 19 deletions lib/platform/gitea/gitea-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URLSearchParams } from 'url';
import { BranchStatus, PrState } from '../../types';
import { GiteaHttp, GiteaHttpOptions } from '../../util/http/gitea';
import { getQueryString } from '../../util/url';
import { PrReviewersParams } from './types';

const giteaHttp = new GiteaHttp();
Expand Down Expand Up @@ -192,20 +192,6 @@ const commitStatusStates: CommitStatusType[] = [
'error',
];

function queryParams(params: Record<string, any>): URLSearchParams {
const usp = new URLSearchParams();
for (const [k, v] of Object.entries(params)) {
if (Array.isArray(v)) {
for (const item of v) {
usp.append(k, item.toString());
}
} else {
usp.append(k, v.toString());
}
}
return usp;
}

export async function getCurrentUser(
options?: GiteaHttpOptions
): Promise<User> {
Expand All @@ -218,7 +204,7 @@ export async function searchRepos(
params: RepoSearchParams,
options?: GiteaHttpOptions
): Promise<Repo[]> {
const query = queryParams(params).toString();
const query = getQueryString(params);
const url = `repos/search?${query}`;
const res = await giteaHttp.getJson<RepoSearchResults>(url, {
...options,
Expand Down Expand Up @@ -249,7 +235,7 @@ export async function getRepoContents(
ref?: string,
options?: GiteaHttpOptions
): Promise<RepoContents> {
const query = queryParams(ref ? { ref } : {}).toString();
const query = getQueryString(ref ? { ref } : {});
const url = `repos/${repoPath}/contents/${urlEscape(filePath)}?${query}`;
const res = await giteaHttp.getJson<RepoContents>(url, options);

Expand Down Expand Up @@ -342,7 +328,7 @@ export async function searchPRs(
params: PRSearchParams,
options?: GiteaHttpOptions
): Promise<PR[]> {
const query = queryParams(params).toString();
const query = getQueryString(params);
const url = `repos/${repoPath}/pulls?${query}`;
const res = await giteaHttp.getJson<PR[]>(url, {
...options,
Expand Down Expand Up @@ -397,7 +383,7 @@ export async function searchIssues(
params: IssueSearchParams,
options?: GiteaHttpOptions
): Promise<Issue[]> {
const query = queryParams({ ...params, type: 'issues' }).toString();
const query = getQueryString({ ...params, type: 'issues' });
const url = `repos/${repoPath}/issues?${query}`;
const res = await giteaHttp.getJson<Issue[]>(url, {
...options,
Expand Down
3 changes: 3 additions & 0 deletions lib/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe('platform/gitlab', () => {
httpMock.reset();
httpMock.setup();
});
afterEach(() => {
httpMock.reset();
});

describe('initPlatform()', () => {
it(`should throw if no token`, async () => {
Expand Down
10 changes: 5 additions & 5 deletions lib/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import URL, { URLSearchParams } from 'url';
import URL from 'url';
import is from '@sindresorhus/is';
import delay from 'delay';
import semver from 'semver';
Expand All @@ -21,7 +21,7 @@ import * as hostRules from '../../util/host-rules';
import { HttpResponse } from '../../util/http';
import { GitlabHttp, setBaseUrl } from '../../util/http/gitlab';
import { sanitize } from '../../util/sanitize';
import { ensureTrailingSlash } from '../../util/url';
import { ensureTrailingSlash, getQueryString } from '../../util/url';
import {
BranchStatusConfig,
CreatePRConfig,
Expand Down Expand Up @@ -384,7 +384,7 @@ async function fetchPrList(): Promise<Pr[]> {
// default: `scope=created_by_me`
searchParams.scope = 'all';
}
const query = new URLSearchParams(searchParams).toString();
const query = getQueryString(searchParams);
const urlString = `projects/${config.repository}/merge_requests?${query}`;
try {
const res = await gitlabApi.getJson<
Expand Down Expand Up @@ -710,11 +710,11 @@ export async function setBranchStatus({

export async function getIssueList(): Promise<GitlabIssue[]> {
if (!config.issueList) {
const query = new URLSearchParams({
const query = getQueryString({
per_page: '100',
author_id: `${authorId}`,
state: 'opened',
}).toString();
});
const res = await gitlabApi.getJson<{ iid: number; title: string }[]>(
`projects/${config.repository}/issues?${query}`,
{
Expand Down

0 comments on commit cc81ca2

Please sign in to comment.