Skip to content

Commit

Permalink
Merge pull request #351 from 1024pix/feature/PIX-9190
Browse files Browse the repository at this point in the history
PIX-9190 : Enrichir le logger de pix bot
  • Loading branch information
alipix committed Jan 22, 2024
2 parents 59b8246 + 19f224c commit 5b7bd33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions common/services/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ async function _getTagCommitUrl({ owner, repo, tagName }) {
const tags = await _getTags(owner, repo);
const tag = tags.find((tag) => tag.name === tagName);
if (!tag) {
logger.error(`Could not find the tag ${tagName} on ${owner}/${repo}`);
throw new Error(`Could not find the tag ${tagName} on ${owner}/${repo}`);
}
return tag.commit.url;
Expand Down
23 changes: 20 additions & 3 deletions common/services/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ module.exports = {
const repositoryURL = `https://${config.github.token}@github.com/${config.github.owner}/${sanitizedRepoName}.git`;
const args = [config.github.owner, sanitizedRepoName, sanitizedReleaseType, branchName, repositoryURL];
const newPackageVersion = await _runScriptWithArgument(RELEASE_PIX_SCRIPT, ...args);
logger.ok({
event: 'release',
message:
'Type: ' +
releaseType +
' , reponame ' +
repoName +
' , Repo URL : ' +
repositoryURL +
' , Package version : ' +
newPackageVersion,
});
return newPackageVersion;
} catch (err) {
logger.error({ event: 'release', message: err });
Expand All @@ -67,9 +79,14 @@ module.exports = {
const sanitizedReleaseTag = _sanitizedArgument(releaseTag);
const sanitizedRepoName = _sanitizedArgument(repoName);
const sanitizedAppName = _sanitizedArgument(appName);
const client = await ScalingoClient.getInstance(environment);

return client.deployFromArchive(sanitizedAppName, sanitizedReleaseTag, sanitizedRepoName);
try {
const client = await ScalingoClient.getInstance(environment);
logger.info('Deploy : ' + sanitizedAppName + ' | Tag ' + sanitizedReleaseTag + ' | Repo : ', sanitizedRepoName);
return client.deployFromArchive(sanitizedAppName, sanitizedReleaseTag, sanitizedRepoName);
} catch (err) {
logger.error({ event: 'deploy', message: err });
throw err;
}
},

_runScriptWithArgument,
Expand Down
8 changes: 8 additions & 0 deletions common/services/scalingo-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ScalingoClient {
static async getInstance(environment, injectedClient = scalingo) {
const { token, apiUrl } = config.scalingo[environment];
if (!token || !apiUrl) {
logger.error(`Scalingo credentials missing for environment ${environment}`);
throw new Error(`Scalingo credentials missing for environment ${environment}`);
}
const client = await injectedClient.clientFromToken(token, { apiUrl });
Expand All @@ -22,9 +23,11 @@ class ScalingoClient {

async deployFromArchive(pixApp, releaseTag, repository = config.github.repository, options = DEFAULT_OPTS) {
if (!pixApp) {
logger.error('No application to deploy.');
throw new Error('No application to deploy.');
}
if (!releaseTag) {
logger.error('No release tag to deploy.');
throw new Error('No release tag to deploy.');
}

Expand All @@ -51,6 +54,7 @@ class ScalingoClient {
throw new Error(`Unable to deploy ${scalingoApp} ${releaseTag}`);
}

logger.info(`Deployment of ${scalingoApp} ${releaseTag} has been requested`);
return `Deployment of ${scalingoApp} ${releaseTag} has been requested`;
}

Expand All @@ -70,6 +74,9 @@ class ScalingoClient {
if (err.status === 404) {
return false;
}
logger.error(
`Impossible to get info for RA ${reviewAppName}. Scalingo API returned ${err.status} : ${err.message}`,
);
throw new Error(
`Impossible to get info for RA ${reviewAppName}. Scalingo API returned ${err.status} : ${err.message}`,
);
Expand Down Expand Up @@ -138,6 +145,7 @@ class ScalingoClient {
try {
const { id } = await this.client.Apps.create(app);
await this.client.Apps.update(id, appSettings);
logger.ok({ event: 'scalingo', message: `${app.name} created` });
return id;
} catch (e) {
logger.error({ event: 'scalingo', message: e });
Expand Down

0 comments on commit 5b7bd33

Please sign in to comment.