-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mhub/feat/1817-add-pipeline
feat: Added travis
- Loading branch information
Showing
6 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Config files used for IDEs, editors, linters and other tools | ||
|
||
- `gitlint` - config for the `gitlint` linter | ||
- `githooks` - useful git hooks (optional - needs to be locally setup if wanted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
To use these, copy them into `.git/hooks` | ||
|
||
|
||
### `commit-msg` | ||
This will run the `gitlint` linter on your commit messages while you write them, so you can check them locally before pushing them for Travis to check. | ||
|
||
#### Pre-reqs: | ||
- Python | ||
- `pip install gitlint` | ||
|
||
#### Install: | ||
- `cp config/githooks/commit-msg .git/hooks/.` | ||
|
||
#### Uninstall: | ||
- `rm .git/hooks/commit-msg` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/sh | ||
### gitlint commit-msg hook start ### | ||
|
||
# Determine whether we have a tty available by trying to access it. | ||
# This allows us to deal with UI based gitclient's like Atlassian SourceTree. | ||
# NOTE: "exec < /dev/tty" sets stdin to the keyboard | ||
stdin_available=1 | ||
(exec < /dev/tty) 2> /dev/null || stdin_available=0 | ||
|
||
if [ $stdin_available -eq 1 ]; then | ||
# Set bash color codes in case we have a tty | ||
RED="\033[31m" | ||
YELLOW="\033[33m" | ||
GREEN="\033[32m" | ||
END_COLOR="\033[0m" | ||
|
||
# Now that we know we have a functional tty, set stdin to it so we can ask the user questions :-) | ||
exec < /dev/tty | ||
else | ||
# Unset bash colors if we don't have a tty | ||
RED="" | ||
YELLOW="" | ||
GREEN="" | ||
END_COLOR="" | ||
fi | ||
|
||
run_gitlint(){ | ||
echo "gitlint: checking commit message..." | ||
cat "$1" | python -m gitlint.cli --config ./config/gitlint/gitlint.cfg | ||
gitlint_exit_code=$? | ||
} | ||
|
||
# Prompts a given yes/no question. | ||
# Returns 0 if user answers yes, 1 if no | ||
# Reprompts if different answer | ||
ask_yes_no_edit(){ | ||
ask_yes_no_edit_result="no" | ||
# If we don't have a stdin available, then just return "No". | ||
if [ $stdin_available -eq 0 ]; then | ||
ask_yes_no_edit_result="no" | ||
return; | ||
fi | ||
# Otherwise, ask the question until the user answers yes or no | ||
question="$1" | ||
while true; do | ||
read -p "$question" yn | ||
case $yn in | ||
[Yy]* ) ask_yes_no_edit_result="yes"; return;; | ||
[Nn]* ) ask_yes_no_edit_result="no"; return;; | ||
[Ee]* ) ask_yes_no_edit_result="edit"; return;; | ||
esac | ||
done | ||
} | ||
|
||
run_gitlint "$1" | ||
|
||
while [ $gitlint_exit_code -gt 0 ]; do | ||
echo "-----------------------------------------------" | ||
echo "gitlint: ${RED}Your commit message contains the above violations.${END_COLOR}" | ||
ask_yes_no_edit "Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] " | ||
if [ $ask_yes_no_edit_result = "yes" ]; then | ||
exit 0 | ||
elif [ $ask_yes_no_edit_result = "edit" ]; then | ||
EDITOR=${EDITOR:-vim} | ||
$EDITOR "$1" | ||
run_gitlint "$1" | ||
else | ||
echo "Commit aborted." | ||
echo "Your commit message: " | ||
echo "-----------------------------------------------" | ||
cat "$1" | ||
echo "-----------------------------------------------" | ||
|
||
exit $gitlint_exit_code | ||
fi | ||
done | ||
|
||
echo "gitlint: ${GREEN}OK${END_COLOR} (no violations in commit message)" | ||
exit 0 | ||
|
||
### gitlint commit-msg hook end ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Config for linting git commit messages | ||
# -------------------------------------- | ||
# | ||
# gitlint's default validations are based on "well-known community standards" | ||
# including: | ||
# https://chris.beams.io/posts/git-commit/ | ||
# https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html | ||
# http://addamhardy.com/2013/06/05/good-commit-messages-and-enforcing-them-with-git-hooks.html | ||
# | ||
# As such, overrides here are kept to an absolute minimum. | ||
# But a few are useful... | ||
|
||
# | ||
# Adding a couple of custom rules - see the comments there for more detail | ||
[general] | ||
extra-path=config/gitlint/rules | ||
|
||
# | ||
# Adding the list of standard types (e.g. "feat", "fix", etc.) for titles from | ||
# https://pages.github.ibm.com/the-playbook/developer-guide/delivering-code-command-line/#type | ||
# to make sure that we stick to the list in the playbook | ||
[title-match-regex] | ||
regex=^(feat|fix|docs|style|refactor|perf|test|chore)(\(.*\))?: .* | ||
|
||
# | ||
# Making the email regex a little more IBM-specific to help people who accidentally | ||
# leave personal email addresses like bob.smith@gmail.com in their git config | ||
[author-valid-email] | ||
regex=[^@]+@(uk.)?ibm.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" Custom gitlint rules | ||
These are Python implementations of some of the guidelines described in | ||
https://pages.github.ibm.com/the-playbook/developer-guide/delivering-code-command-line/#commit-message-format | ||
""" | ||
|
||
from gitlint.rules import CommitRule, RuleViolation | ||
from gitlint.options import IntOption | ||
import re | ||
|
||
|
||
|
||
class SignedOffBy(CommitRule): | ||
""" This rule will enforce that each commit contains a "Signed-off-by" line with a name and email address. | ||
https://pages.github.ibm.com/the-playbook/developer-guide/delivering-code-command-line/#developer-certificate-of-origin | ||
""" | ||
|
||
id = "QP1" | ||
name = "body-requires-signed-off-by" | ||
|
||
signoffregex = re.compile('^(DCO 1.1 )?Signed-off-by: .* <[^@ ]+@[^@ ]+\.[^@ ]+>') | ||
|
||
def validate(self, commit): | ||
for line in commit.message.body: | ||
if self.signoffregex.match(line): | ||
return | ||
|
||
return [RuleViolation(self.id, "Body does not contain a valid 'Signed-off-by' line. See https://pages.github.ibm.com/the-playbook/developer-guide/delivering-code-command-line/#developer-certificate-of-origin", line_nr=1)] | ||
|
||
|
||
class GithubIssue(CommitRule): | ||
""" This rule will enforce that each commit is associated with a Github issue that explains what the commit is for. | ||
""" | ||
|
||
id = "QP2" | ||
name = "commit-require-github-issue" | ||
|
||
githubissueregex = re.compile('(Resolves|Closes|Contributes to|Reverts):? [a-z\-/]*#[0-9]+') | ||
|
||
def validate(self, commit): | ||
for line in commit.message.body: | ||
if self.githubissueregex.match(line): | ||
return | ||
|
||
return [RuleViolation(self.id, "Body does not contain a github issue reference", line_nr=1)] | ||
|
||
|
||
|
Binary file not shown.