Check if on default branch before uploading database

This commit is contained in:
Robert 2021-06-16 14:17:50 +01:00
parent 429471162a
commit d693b3cb0d
6 changed files with 49 additions and 5 deletions

10
lib/analyze-action.js generated
View file

@ -34,6 +34,11 @@ async function sendStatusReport(startedAt, stats, error) {
await actionsUtil.sendStatusReport(statusReport);
}
async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
if (!(await actionsUtil.isAnalyzingDefaultBranch())) {
// We only want to upload a database if we are analyzing the default branch.
logger.debug("Not analyzing default branch. Skipping upload.");
return;
}
const client = api_client_1.getApiClient(apiDetails);
const optInResponse = await client.request("GET /repos/:owner/:repo/code-scanning/databases", {
owner: repositoryNwo.owner,
@ -57,7 +62,10 @@ async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
repo: repositoryNwo.repo,
data: payload,
});
if (uploadResponse.status !== 201) {
if (uploadResponse.status === 201) {
logger.debug(`Successfully uploaded database for ${language}`);
}
else {
// Log a warning but don't fail the workflow
logger.warning(`Failed to upload database for ${language}. ${uploadResponse.data}`);
}