Skip to content

Commit

Permalink
fix: refactor logging (#146)
Browse files Browse the repository at this point in the history
fix: refactor logging
  • Loading branch information
adong authored Nov 21, 2019
2 parents 384a1d7 + 76385eb commit e2f56db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
46 changes: 23 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const joi = require('joi');
const schema = require('screwdriver-data-schema');
const Scm = require('screwdriver-scm-base');
const crypto = require('crypto');
const winston = require('winston');
const logger = require('screwdriver-logger');
const DEFAULT_AUTHOR = {
avatar: 'https://cd.screwdriver.cd/assets/unknown_user.png',
name: 'n/a',
Expand Down Expand Up @@ -167,7 +167,7 @@ class GithubScm extends Scm {

repoFullName = repo.data.full_name;
} catch (err) {
winston.error('Failed to lookupScmUri: ', err);
logger.error('Failed to lookupScmUri: ', err);
throw err;
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ class GithubScm extends Scm {

return screwdriverHook;
} catch (err) {
winston.error('Failed to findWebhook: ', err);
logger.error('Failed to findWebhook: ', err);
throw err;
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ class GithubScm extends Scm {

return hooks.data;
} catch (err) {
winston.error('Failed to createWebhook: ', err);
logger.error('Failed to createWebhook: ', err);
throw err;
}
}
Expand Down Expand Up @@ -512,7 +512,7 @@ class GithubScm extends Scm {
userProfile: pullRequest.user.html_url
}));
} catch (err) {
winston.error('Failed to getOpenedPRs: ', err);
logger.error('Failed to getOpenedPRs: ', err);
throw err;
}
}
Expand Down Expand Up @@ -552,14 +552,14 @@ class GithubScm extends Scm {
} catch (err) {
// Suspended user
if (err.message.match(/suspend/i)) {
winston.info(
logger.info(
`User's account suspended for ${config.scmUri}, ` +
'it will be removed from pipeline admins.');

return { admin: false, push: false, pull: false };
}

winston.error('Failed to getPermissions: ', err);
logger.error('Failed to getPermissions: ', err);
throw err;
}
}
Expand Down Expand Up @@ -600,7 +600,7 @@ class GithubScm extends Scm {

return result;
} catch (err) {
winston.error('Failed to getOrgPermissions: ', err);
logger.error('Failed to getOrgPermissions: ', err);
throw err;
}
}
Expand Down Expand Up @@ -644,7 +644,7 @@ class GithubScm extends Scm {

return branch.data.commit.sha;
} catch (err) {
winston.error('Failed to getCommitSha: ', err);
logger.error('Failed to getCommitSha: ', err);
throw err;
}
}
Expand Down Expand Up @@ -693,7 +693,7 @@ class GithubScm extends Scm {
}
throw new Error(`Cannot handle ${refObj.data.object.type} type`);
} catch (err) {
winston.error('Failed to getCommitRefSha: ', err);
logger.error('Failed to getCommitRefSha: ', err);
throw err;
}
}
Expand Down Expand Up @@ -741,7 +741,7 @@ class GithubScm extends Scm {
return status ? status.data : undefined;
} catch (err) {
if (err.status !== 422) {
winston.error('Failed to updateCommitStatus: ', err);
logger.error('Failed to updateCommitStatus: ', err);
throw err;
}

Expand Down Expand Up @@ -791,7 +791,7 @@ class GithubScm extends Scm {

return Buffer.from(file.data.content, file.data.encoding).toString();
} catch (err) {
winston.error('Failed to getFile: ', err);
logger.error('Failed to getFile: ', err);
throw err;
}
}
Expand Down Expand Up @@ -833,7 +833,7 @@ class GithubScm extends Scm {
throw new Error(`Cannot find repository ${checkoutUrl}`);
}

winston.error('Failed to getRepoId: ', err);
logger.error('Failed to getRepoId: ', err);
throw new Error(err);
}
}
Expand Down Expand Up @@ -863,7 +863,7 @@ class GithubScm extends Scm {
url: user.data.html_url
};
} catch (err) {
winston.error('Failed to decorateAuthor: ', err);
logger.error('Failed to decorateAuthor: ', err);
throw err;
}
}
Expand Down Expand Up @@ -930,7 +930,7 @@ class GithubScm extends Scm {
url: commit.data.html_url
};
} catch (err) {
winston.error('Failed to decorateCommit: ', err);
logger.error('Failed to decorateCommit: ', err);
throw err;
}
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ class GithubScm extends Scm {

return files.map(file => file.filename);
} catch (err) {
winston.error('Failed to getChangedFiles: ', err);
logger.error('Failed to getChangedFiles: ', err);

return [];
}
Expand Down Expand Up @@ -1150,7 +1150,7 @@ class GithubScm extends Scm {
const refType = hoek.reach(webhookPayload, 'ref_type');

if (refType !== 'tag') {
winston.info('%s event of %s is not available yet in scm-github plugin',
logger.info('%s event of %s is not available yet in scm-github plugin',
type, refType);

return null;
Expand All @@ -1169,7 +1169,7 @@ class GithubScm extends Scm {
}

default:
winston.info('%s event is not available yet in scm-github plugin', type);
logger.info('%s event is not available yet in scm-github plugin', type);

return null;
}
Expand Down Expand Up @@ -1281,7 +1281,7 @@ class GithubScm extends Scm {
baseBranch: pullRequestInfo.data.base.ref
};
} catch (err) {
winston.error('Failed to getPrInfo: ', err);
logger.error('Failed to getPrInfo: ', err);
throw err;
}
}
Expand Down Expand Up @@ -1321,7 +1321,7 @@ class GithubScm extends Scm {
username: pullRequestComment.data.user.login
};
} catch (err) {
winston.error('Failed to addPRComment: ', err);
logger.error('Failed to addPRComment: ', err);

return null;
}
Expand Down Expand Up @@ -1360,7 +1360,7 @@ class GithubScm extends Scm {

return result.checkoutUrl.startsWith(checkoutSshHost);
} catch (err) {
winston.error('Failed to run canHandleWebhook', err);
logger.error('Failed to run canHandleWebhook', err);

return false;
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ class GithubScm extends Scm {

return branches.map(branch => ({ name: hoek.reach(branch, 'name') }));
} catch (err) {
winston.error('Failed to findBranches: ', err);
logger.error('Failed to findBranches: ', err);
throw err;
}
}
Expand All @@ -1423,7 +1423,7 @@ class GithubScm extends Scm {
page: 1,
token: config.token
}).catch((err) => {
winston.error('Failed to getBranchList: ', err);
logger.error('Failed to getBranchList: ', err);
throw err;
});
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"chai": "^3.5.0",
"eslint": "^4.19.1",
"eslint-config-screwdriver": "^3.0.1",
"jenkins-mocha": "^7.0.0",
"jenkins-mocha": "^8.0.0",
"mockery": "^2.0.0",
"sinon": "^7.2.7"
},
Expand All @@ -46,7 +46,7 @@
"joi": "^13.7.0",
"screwdriver-data-schema": "^18.46.13",
"screwdriver-scm-base": "^5.2.0",
"winston": "^3.2.1"
"screwdriver-logger": "^1.0.0"
},
"release": {
"debug": false,
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('index', function () {
};

mockery.registerMock('@octokit/rest', githubMockClass);
mockery.registerMock('winston', winstonMock);
mockery.registerMock('screwdriver-logger', winstonMock);

// eslint-disable-next-line global-require
GithubScm = require('../');
Expand Down

0 comments on commit e2f56db

Please sign in to comment.