Skip to content

Commit

Permalink
Apply code review suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
Gabriel-Ladzaretti and viceice committed Sep 7, 2022
1 parent f455072 commit 7d387bc
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export function massageMarkdown(input: string): string {
'rename PR to start with "rebase!"'
)
.replace(regEx(`\n---\n\n.*?<!-- rebase-check -->.*?\n`), '')
.replace(regEx(/<!--renovate-(debug|config-hash):.*?-->/), '');
.replace(regEx(/<!--renovate-(debug|config-hash):.*?-->/g), '');
}

/* istanbul ignore next */
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export function massageMarkdown(input: string): string {
.replace(regEx(/<\/?details>/g), '')
.replace(regEx(`\n---\n\n.*?<!-- rebase-check -->.*?\n`), '')
.replace(regEx(/\]\(\.\.\/pull\//g), '](../../pull-requests/')
.replace(regEx(/<!--renovate-(debug|config-hash):.*?-->/), '');
.replace(regEx(/<!--renovate-(debug|config-hash):.*?-->/g), '');
}

export async function ensureIssue({
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/platform/pr-body.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import hasha from 'hasha';
import { toBase64 } from '../../util/string';
import { getPrBodyStruct, hashBody } from './pr-body';

describe('modules/platform/pr-body', () => {
Expand Down Expand Up @@ -84,8 +83,7 @@ describe('modules/platform/pr-body', () => {
it('returns raw config hash', () => {
const config = '{}';
const rawConfigHash = hasha(config, { algorithm: 'sha256' });
const encodedHash = toBase64(rawConfigHash);
const input = `<!--renovate-config-hash:${encodedHash})-->`;
const input = `<!--renovate-config-hash:${rawConfigHash}-->`;
const hash = hashBody(input);
expect(getPrBodyStruct(input)).toEqual({
hash,
Expand Down
8 changes: 3 additions & 5 deletions lib/modules/platform/pr-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ export const prDebugDataRe = regEx(
/\n?<!--renovate-debug:(?<payload>.*?)-->\n?/
);

export const renovateConfigHashRe = regEx(
const renovateConfigHashRe = regEx(
/\n?<!--renovate-config-hash:(?<payload>.*?)-->\n?/
);

export const prCheckboxRe = regEx(
/- (?<checkbox>\[[\sx]]) <!-- rebase-check -->/
);
const prCheckboxRe = regEx(/- (?<checkbox>\[[\sx]]) <!-- rebase-check -->/);

function noWhitespaceOrHeadings(input: string): string {
return input.replace(regEx(/\r?\n|\r|\s|#/g), '');
Expand Down Expand Up @@ -70,7 +68,7 @@ export function getPrBodyStruct(

const rawConfigHash = getRenovateConfigHashPayload(body);
if (rawConfigHash) {
result.rawConfigHash = fromBase64(rawConfigHash);
result.rawConfigHash = rawConfigHash;
}

const debugPayload = getRenovateDebugPayload(body);
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export async function renovateRepository(
logger.debug('Using localDir: ' + localDir);
config = await initRepo(config);
addSplit('init');
const preformExtract =
const performExtract =
config.repoIsOnboarded! || OnboardingState.prUpdateRequested;
const { branches, branchList, packageFiles } = preformExtract
const { branches, branchList, packageFiles } = performExtract
? await extractDependencies(config)
: emptyExtract(config);
if (
Expand All @@ -56,7 +56,7 @@ export async function renovateRepository(
const res = await updateRepo(config, branches);
setMeta({ repository: config.repository });
addSplit('update');
if (preformExtract) {
if (performExtract) {
await setBranchCache(branches); // update branch cache if preformed extraction
}
if (res === 'automerged') {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/onboarding/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('workers/repository/onboarding/branch/index', () => {

await checkOnboardingBranch(config);

expect(logger.debug).toHaveBeenCalledWith(
expect(logger.trace).toHaveBeenCalledWith(
`Platform '${pl}' does not support extended markdown`
);
expect(OnboardingState.prUpdateRequested).toBeTrue();
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/onboarding/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export async function checkOnboardingBranch(
if (onboardingPr) {
const pl = GlobalConfig.get('platform')!;
const { rebaseRequested, rawConfigHash } = onboardingPr.bodyStruct ?? {};
if (!['github', 'gitlab'].includes(pl)) {
logger.debug(`Platform '${pl}' does not support extended markdown`);
if (!['github', 'gitlab', 'gitea'].includes(pl)) {
logger.trace(`Platform '${pl}' does not support extended markdown`);
OnboardingState.prUpdateRequested = true;
} else if (is.nullOrUndefined(rebaseRequested)) {
logger.debug('No rebase checkbox was found in the onboarding PR');
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/onboarding/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export class OnboardingState {
private static updateRequested = false;

static get prUpdateRequested(): boolean {
logger.debug(
logger.trace(
{ value: this.updateRequested },
'Get OnboardingState.prUpdateRequested'
);
return this.updateRequested;
}

static set prUpdateRequested(value: boolean) {
logger.debug({ value }, 'Set OnboardingState.prUpdateRequested');
logger.trace({ value }, 'Set OnboardingState.prUpdateRequested');
this.updateRequested = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you need any further assistance then you can also [request help here](https:/
<!--renovate-config-hash:ZTNiMGM0NDI5OGZjMWMxNDlhZmJmNGM4OTk2ZmI5MjQyN2FlNDFlNDY0OWI5MzRjYTQ5NTk5MWI3ODUyYjg1NQ==-->"
<!--renovate-config-hash:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855-->"
`;

exports[`workers/repository/onboarding/pr/index ensureOnboardingPr() creates PR with footer and header using templating 1`] = `
Expand Down Expand Up @@ -69,7 +69,7 @@ If you need any further assistance then you can also [request help here](https:/
And this is a footer for repository:test baseBranch:some-branch
<!--renovate-config-hash:ZTNiMGM0NDI5OGZjMWMxNDlhZmJmNGM4OTk2ZmI5MjQyN2FlNDFlNDY0OWI5MzRjYTQ5NTk5MWI3ODUyYjg1NQ==-->"
<!--renovate-config-hash:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855-->"
`;

exports[`workers/repository/onboarding/pr/index ensureOnboardingPr() creates PR with footer and header with trailing and leading newlines 1`] = `
Expand Down Expand Up @@ -110,5 +110,5 @@ There should be several empty lines at the end of the PR
<!--renovate-config-hash:ZTNiMGM0NDI5OGZjMWMxNDlhZmJmNGM4OTk2ZmI5MjQyN2FlNDFlNDY0OWI5MzRjYTQ5NTk5MWI3ODUyYjg1NQ==-->"
<!--renovate-config-hash:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855-->"
`;
2 changes: 1 addition & 1 deletion lib/workers/repository/onboarding/pr/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('workers/repository/onboarding/pr/index', () => {
let branches: BranchConfig[];

const bodyStruct = {
hash: '852f207771e73bd098c86c641fc7c1881529f859c3b078359c79b26565a5179c',
hash: '6aa71f8cb7b1503b883485c8f5bd564b31923b9c7fa765abe2a7338af40e03b1',
};

beforeEach(() => {
Expand Down
3 changes: 1 addition & 2 deletions lib/workers/repository/onboarding/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
isBranchConflicted,
isBranchModified,
} from '../../../../util/git';
import { toBase64 } from '../../../../util/string';
import * as template from '../../../../util/template';
import type { BranchConfig } from '../../../types';
import {
Expand Down Expand Up @@ -135,7 +134,7 @@ If you need any further assistance then you can also [request help here](${
const existingContents =
(await getFile(configFile, config.onboardingBranch)) ?? '';
const hash = toSha256(existingContents);
prBody += `\n<!--renovate-config-hash:${toBase64(hash)}-->`;
prBody += `\n<!--renovate-config-hash:${hash}-->`;

logger.trace('prBody:\n' + prBody);

Expand Down

0 comments on commit 7d387bc

Please sign in to comment.