Skip to content

Conversation

@welcoMattic
Copy link
Collaborator

@welcoMattic welcoMattic commented Nov 21, 2016

  • Refacto
  • Replace emojis list with gitmoji
  • Add --init option

Ref. #3

@welcoMattic welcoMattic mentioned this pull request Nov 21, 2016
@tjoskar
Copy link
Owner

tjoskar commented Nov 21, 2016

Wow! This looks amazing! Thanks! I will have a look and get back to you BUT this PR will be accepted!

.travis.yml Outdated

node_js:
- 6
- 4
Copy link
Owner

Choose a reason for hiding this comment

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

Do we really need to use v4 and v6? I mean, we are going to use the same version of eslint regardless of node version, right? So if it works in v6 it is going to work in v4 and vice versa.

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, but as 4.x is LTS, testing on it is to be sure that we support this LTS.

Copy link
Owner

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but eslint will check the file statically without ever executing any code so even if eslint is running under node 4.x and returning that the code is flawless does not necessarily mean that it will work for v4.x.

What we really want is something like: https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unsupported-features.md

.travis.yml Outdated
- npm install -g eslint

install:
- npm install --only=production
Copy link
Owner

Choose a reason for hiding this comment

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

Since you added a yarn.lock file, we should use yarn and according to this blog post: https://blog.travis-ci.com/2016-11-21-travis-ci-now-supports-yarn travis will always use yarn if there is a yarn.lock and we don't override the install script. So I think we should replace the command with yarn install --production.

LICENSE Outdated
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Oskar Karlsson
Copy link
Owner

Choose a reason for hiding this comment

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

You should add your name here. Eg, Oskar Karlsson, Mathieu Santo Stefano--Féron

# Gitmoji-commit-hook

> Add emoji to your commits
[![Build Status](https://travis-ci.org/welcoMattic/gitmoji-commit-hook.svg?branch=master)](https://travis-ci.org/welcoMattic/gitmoji-commit-hook)
Copy link
Owner

Choose a reason for hiding this comment

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

We need to update all paths after the merge. I can fix that.

package.json Outdated
"description": "Start the commit message with an applicable emoji",
"main": "index.js",
"name": "gitmoji-commit-hook",
"version": "1.1.0",
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should bump the version to 2.0.0 since the tool now requirer a internet connection AND do not ask for a issue number any more.

bin/index.js Outdated
}
});

fs.chmod(`${path}/prepare-commit-msg`, '755', (err) => {
Copy link
Owner

Choose a reason for hiding this comment

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

How can this even work 😉. You call fs.writeFile which will create a file asynchronous but at the same time you will try to change the chmod. It works but I can't say why. I would have called fs.chmod in the callback of fs.writeFile.

console.error(chalk.red('🚨 ERROR: The directory is not a git repository.'));
}
} else {
axios.get(gitmojis)
Copy link
Owner

Choose a reason for hiding this comment

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

We should cache the file so we don't are dependent of internet when we are going to commit. I'm thinking of something like this:

1. check if gitmojis.json exist on disk
  a. if it exist, use it but if the file is older than 3 days: try to download a new file in the background.
  b. if it don't exist, download the file and use it.

I will create a issue so we can fix this in the feature. We don't need to fix this now.

name: gitmoji.emoji + ' ' + gitmoji.description,
value: gitmoji.emoji
};
})
Copy link
Owner

Choose a reason for hiding this comment

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

You have removed the question about reference issue number. Was that intentionally?

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, I like KISS principle, so our hook aim is to add emoji to commit message. As gitmoji-cli allows to add issue number, commit title, commit message etc ... I think we dont need to ask for issue number anymore.

Copy link
Owner

Choose a reason for hiding this comment

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

Far enough.

bin/index.js Outdated
});

if(/COMMIT_EDITMSG/g.test(process.argv[2])) {
inquirer.prompt(questions).then((answers) => {
Copy link
Owner

Choose a reason for hiding this comment

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

We should return inquirer.prompt so we can catch (line 59) any errors that inquirer might give.

bin/index.js Outdated
}
})
.catch(err => {
console.log(err);
Copy link
Owner

Choose a reason for hiding this comment

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

Should use console.error(chalk.red('🚨 ERROR: ${err}.'));

Copy link
Owner

Choose a reason for hiding this comment

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

What do you think of creating a error-handler method. eg.

const errorHandler = error => {
  console.error(chalk.red(`🚨  ERROR: ${error}`));
  process.exit(1);
};

So we can handel all error message in the same manner.

@tjoskar
Copy link
Owner

tjoskar commented Nov 22, 2016

Looking good. I just have a few question, see above.

@welcoMattic
Copy link
Collaborator Author

@tjoskar I just fix things after your feedback, thank you for it!

@tjoskar
Copy link
Owner

tjoskar commented Nov 22, 2016

@welcoMattic, great but I still thinks we need to check if the file exists before we override the content, see #2 (comment)

Something like this:

if (process.argv[2] === '--init') {
  if (!pathExists.sync('.git')) {
    errorHandler('The directory is not a git repository.');
  }
  if (fileExists(${path}/prepare-commit-msg)) {
    errorHandler(`A prepare-commit hook already exists, please remove the hook (rm .git/hooks/prepare-commit-msg) or install gitmoji-commit-hook manually by adding the following content info ${${path}/prepare-commit-msg}: \nexec < /dev/tty\ngitmoji-commit-hook $1`);
  }

  fs.writeFile(${path}/prepare-commit-msg, `#!/bin/sh\nexec < /dev/tty\ngitmoji-commit-hook $1`, (err) => {
    if (err) {
      errorHandler(err);
    } else {
      fs.chmod(${path}/prepare-commit-msg, '755', (err) => {
        if (err) {
          errorHandler(err);
        } else {
          console.log(`${chalk.green('🎉  SUCCESS 🎉')}  gitmoji-commit-hook initialized with success.`);
        }
      });
    }
  });
} else {
  axios.get(gitmojis)
  ...

Or what do you think?

@welcoMattic
Copy link
Collaborator Author

@tjoskar Done ;)

@tjoskar tjoskar merged commit 57c7e9f into tjoskar:master Nov 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants