Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: delete cached configFilename #20746

Merged

Conversation

RahulGautamSingh
Copy link
Collaborator

@RahulGautamSingh RahulGautamSingh commented Mar 4, 2023

Changes

  • delete cached config filename if it doesn't exist

Context

  • feat(onboarding): use cache to check if repo is onboarded #20733
  • In the linked PR I have introduced functionality that detects whether repo is onboarded/not using cache. But we do this detection before using API to search for config-file in repo, thus this part of the code won't be executed. And in the case where repo is not onboarded and onboarding cache is valid we skip the part where we delete the cached configFilename
    const cache = getCache();
    if (cache.configFileName) {
    logger.debug('Checking cached config file name');
    try {
    const configFileContent = await platform.getJsonFile(
    cache.configFileName
    );
    if (configFileContent) {
    if (
    cache.configFileName !== 'package.json' ||
    configFileContent.renovate
    ) {
    logger.debug('Existing config file confirmed');
    logger.debug(
    { fileName: cache.configFileName, config: configFileContent },
    'Repository config'
    );
    return true;
    }
    }
    } catch (err) {
    // probably file doesn't exist
    }
    logger.debug('Existing config file no longer exists');
    delete cache.configFileName;
    }

This causes error in the function below when we try to detectRepoFileConfig as we look for a config-file using api but won't find it.
This causes unknown error or file not found error when running on a real repo. So I am adding a try catch to handle the error better.

export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
const cache = getCache();
let { configFileName } = cache;
if (configFileName) {
const configFileRaw = await platform.getRawFile(configFileName);
if (configFileRaw) {
let configFileParsed = JSON5.parse(configFileRaw);
if (configFileName !== 'package.json') {
return { configFileName, configFileRaw, configFileParsed };
}
configFileParsed = configFileParsed.renovate;
return { configFileName, configFileParsed }; // don't return raw 'package.json'
} else {
logger.debug('Existing config file no longer exists');
}
}
configFileName = (await detectConfigFile()) ?? undefined;
if (!configFileName) {
logger.debug('No renovate config file found');
return {};
}

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@RahulGautamSingh RahulGautamSingh changed the title reactor: delete cached configFilename refactor: delete cached configFilename Mar 4, 2023
@RahulGautamSingh RahulGautamSingh marked this pull request as ready for review March 4, 2023 06:44
rarkins
rarkins previously approved these changes Mar 4, 2023
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs coverage

lib/workers/repository/init/merge.ts Show resolved Hide resolved
@rarkins rarkins added this pull request to the merge queue Mar 7, 2023
Merged via the queue into renovatebot:main with commit bccf099 Mar 7, 2023
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 34.158.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

RahulGautamSingh added a commit to RahulGautamSingh/renovate that referenced this pull request Mar 19, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants