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

Github Integration #42

Open
wants to merge 37 commits into
base: integrations
Choose a base branch
from
Open

Conversation

souravdasslg
Copy link
Collaborator

@souravdasslg souravdasslg commented Dec 9, 2019

Pull Request Template

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #43

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit Test
  • Integration Test

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@souravdasslg souravdasslg changed the title [WIP] Github Integration Github Integration Dec 11, 2019
Copy link

@rishabh1403 rishabh1403 left a comment

Choose a reason for hiding this comment

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

There are a couple of comments which applies to multiple files in general. PLease resolve those in all files :)


app.use(pino());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(publicFolder));
// app.use('/api/v1', AuthenticationMiddleware);
app.set('view engine', 'ejs');

Choose a reason for hiding this comment

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

do you need a view engine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, as we are serving our OAuth pages from the backend server. Also, the authorization callbacks are directly handled by our backend. :)


app.use(pino());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(publicFolder));
// app.use('/api/v1', AuthenticationMiddleware);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/thirdparty/views'));
requireAll(modelDirPath);

Choose a reason for hiding this comment

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

all require should happen before any logic. Ideally, they should be the first thing


const AppsCollection = mongoose.model('Apps');
const getApps = (req, res) => {

Choose a reason for hiding this comment

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

add some line breaks, it is not readable

console.log(req.body);
const createdApp = await AppsCollection.create(req.body);
res.send(createdApp);
const generatedResponse = responseLib.generateResponse(false, actionStatus.SUCCESS,

Choose a reason for hiding this comment

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

pass in an object with values instead of multiple params. It's easier to update/ changes params later.
Also the code is more readable


const getEventDetails = (req, res) => {
let eventDetails;
for (const event of IntegrationConfig[req.params.appName].Events) {

Choose a reason for hiding this comment

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

what if IntegrationConfig[req.params.appName].Events is undefined/ null?
What is appName is not present in params. The server will crash. Please handle the errors

@@ -8,7 +8,7 @@ const slackWebHookListener = async (event, authedUsers) => {
};

const gitWebHookListener = (event) => {
console.log(event);
// console.log(event);

Choose a reason for hiding this comment

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

empty function?

@@ -1,7 +1,7 @@
import jwt from 'jsonwebtoken';
import time from './timeLib';

const { JWT_SECRET } = process.env;
const JWT_SECRET = 'zF9?nCmaZH&?fF9';

Choose a reason for hiding this comment

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

This is absolutely wrong.
Putting in secrets in code is not safe


eventEmitter.on('Github:Authorize', async (payload) => {
// eslint-disable-next-line camelcase
const { state, installation_id, code } = payload;

Choose a reason for hiding this comment

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

you can have camelcase using installation_id: installationId

method: 'POST',
headers: { Accept: 'application/json' },
json: {
code,

Choose a reason for hiding this comment

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

put some line breaks please

module.exports = {
path: '/app',
path: '/api/v1',

Choose a reason for hiding this comment

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

assuming you are gonna use path to append to route so you can call something like this
/api/v1/your-path

But this way you are taking away all the benefits. versioning is there for backward compatibility. Once you rename the variable to /api/v2 all previous routes are gone.

Correct me if I made a wrong assumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants