|
5 | 5 | "fmt"
|
6 | 6 | "os"
|
7 | 7 |
|
| 8 | + commitmessage "github.com/NeowayLabs/semantic-release/src/commit-message" |
| 9 | + committype "github.com/NeowayLabs/semantic-release/src/commit-type" |
8 | 10 | "github.com/NeowayLabs/semantic-release/src/files"
|
9 | 11 | "github.com/NeowayLabs/semantic-release/src/git"
|
10 | 12 | "github.com/NeowayLabs/semantic-release/src/log"
|
@@ -37,6 +39,8 @@ func main() {
|
37 | 39 | helpCmd := flag.NewFlagSet("help", flag.ExitOnError)
|
38 | 40 | helpCommitCmd := flag.NewFlagSet("help-cmt", flag.ExitOnError)
|
39 | 41 |
|
| 42 | + commitLint := upgradeVersionCmd.Bool("commit-lint", false, "Only lint commit history if set as true. (default false)") |
| 43 | + branchName := upgradeVersionCmd.String("branch-name", "", "Branch name to be cloned.") |
40 | 44 | gitHost := upgradeVersionCmd.String("git-host", "", "Git host name. I.e.: gitlab.integration-tests.com. (required)")
|
41 | 45 | groupName := upgradeVersionCmd.String("git-group", "", "Git group name. (required)")
|
42 | 46 | projectName := upgradeVersionCmd.String("git-project", "", "Git project name. (required)")
|
@@ -67,15 +71,28 @@ func main() {
|
67 | 71 | case "up":
|
68 | 72 | logger.Info(colorYellow + "\nSemantic Version just started the process...\n\n" + colorReset)
|
69 | 73 |
|
70 |
| - semantic := newSemantic(logger, upgradeVersionCmd, gitHost, groupName, projectName, username, password, upgradePyFile) |
71 |
| - |
72 |
| - if err := semantic.GenerateNewRelease(); err != nil { |
73 |
| - logger.Error(err.Error()) |
74 |
| - os.Exit(1) |
| 74 | + semantic := newSemantic(logger, upgradeVersionCmd, gitHost, groupName, projectName, username, password, upgradePyFile, branchName) |
| 75 | + |
| 76 | + if *commitLint { |
| 77 | + if *branchName == "" { |
| 78 | + logger.Error(colorRed + "\nThe argument -branch-name must be set when --commit-lint is true.\n\n" + colorReset) |
| 79 | + } |
| 80 | + |
| 81 | + logger.Info(colorYellow + "\nSemantic Version commit lint started...\n\n" + colorReset) |
| 82 | + err := semantic.CommitLint() |
| 83 | + if err != nil { |
| 84 | + printCommitTypes() |
| 85 | + printCommitMessageExample() |
| 86 | + os.Exit(1) |
| 87 | + } |
| 88 | + } else { |
| 89 | + if err := semantic.GenerateNewRelease(); err != nil { |
| 90 | + logger.Error(err.Error()) |
| 91 | + os.Exit(1) |
| 92 | + } |
75 | 93 | }
|
76 | 94 |
|
77 | 95 | logger.Info(colorYellow + "\nDone!" + colorReset)
|
78 |
| - |
79 | 96 | case "help":
|
80 | 97 | printMainCommands()
|
81 | 98 | helpCmd.PrintDefaults()
|
@@ -112,7 +129,6 @@ func addFilesToUpgradeList(upgradePyFile *bool, repositoryRootPath string) Upgra
|
112 | 129 | }
|
113 | 130 |
|
114 | 131 | func validateIncomingParams(logger *log.Log, upgradeVersionCmd *flag.FlagSet, gitHost, groupName, projectName, username, password *string, upgradePyFile *bool) {
|
115 |
| - |
116 | 132 | if *gitHost == "" {
|
117 | 133 | logger.Info(colorRed + "Oops! Git host name must be specified." + colorReset + "[docker run neowaylabs/semantic-release up " + colorYellow + "-git-host gitHostNameHere]" + colorReset)
|
118 | 134 | os.Exit(1)
|
@@ -158,44 +174,51 @@ func printCommitTypes() {
|
158 | 174 | fmt.Println(colorYellow + "\n\t* [build]" + colorReset + ": Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)")
|
159 | 175 | fmt.Println(colorYellow + "\t* [ci]" + colorReset + ": Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)")
|
160 | 176 | fmt.Println(colorYellow + "\t* [docs]" + colorReset + ": Documentation only changes")
|
| 177 | + fmt.Println(colorYellow + "\t* [documentation]" + colorReset + ": ||") |
161 | 178 | fmt.Println(colorYellow + "\t* [feat]" + colorReset + ": A new feature")
|
| 179 | + fmt.Println(colorYellow + "\t* [feature]" + colorReset + ": ||") |
162 | 180 | fmt.Println(colorYellow + "\t* [fix]" + colorReset + ": A bug fix")
|
163 | 181 | fmt.Println(colorYellow + "\t* [perf]" + colorReset + ": A code change that improves performance")
|
| 182 | + fmt.Println(colorYellow + "\t* [performance]" + colorReset + ": ||") |
164 | 183 | fmt.Println(colorYellow + "\t* [refactor]" + colorReset + ": A code change that neither fixes a bug nor adds a feature")
|
165 | 184 | fmt.Println(colorYellow + "\t* [style]" + colorReset + ": Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)")
|
166 | 185 | fmt.Println(colorYellow + "\t* [test]" + colorReset + ": Adding missing tests or correcting existing tests")
|
167 | 186 | fmt.Println(colorYellow + "\t* [skip]" + colorReset + ": Skip versioning")
|
168 |
| - fmt.Println(colorYellow + "\t* [skip versioning]" + colorReset + ": Skip versioning") |
169 |
| - fmt.Println(colorYellow + "\t* [breaking change]" + colorReset + ": Change that will require other changes in dependant applications") |
170 |
| - fmt.Println(colorYellow + "\t* [breaking changes]" + colorReset + ": Changes that will require other changes in dependant applications") |
| 187 | + fmt.Println(colorYellow + "\t* [bc]" + colorReset + ": Changes that will require other changes in dependant applications") |
| 188 | + fmt.Println(colorYellow + "\t* [breaking]" + colorReset + ": ||") |
| 189 | + fmt.Println(colorYellow + "\t* [breaking change]" + colorReset + ": ||") |
171 | 190 | }
|
172 | 191 |
|
173 | 192 | func printCommitMessageExample() {
|
174 | 193 | fmt.Println(colorYellow + "\nCOMMIT MESSAGE PATTERN" + colorReset)
|
175 | 194 | fmt.Println("\nThe commit message must follow the pattern below.")
|
176 |
| - fmt.Println("\n\ttype [commit type here], message: Commit subject here.") |
| 195 | + fmt.Println("\n\ttype(optional scope): Commit subject message here.") |
177 | 196 | fmt.Println(colorYellow + "\n\tI.e." + colorReset)
|
178 |
| - fmt.Println("\t\ttype [feat], message: Added new feature to handle postgresql database connection.") |
| 197 | + fmt.Println("\t\tfeat(config): Added new feature to handle configs.") |
179 | 198 |
|
180 |
| - fmt.Println("\n\tNote: The maximum number of characters is 150. If the commit subject exceeds it, it will be cut, keeping only the first 150 characters.") |
| 199 | + fmt.Println("\n\tNote 1: The (scope) is optional. Semantic-release accepts the following pattern: \"type: Commit subject message here\".") |
| 200 | + fmt.Println("\n\tNote 2: The maximum number of characters is 150. If the commit subject exceeds it, it will be cut, keeping only the first 150 characters.") |
181 | 201 | }
|
182 | 202 |
|
183 |
| -func newSemantic(logger *log.Log, upgradeVersionCmd *flag.FlagSet, gitHost, groupName, projectName, username, password *string, upgradePyFile *bool) *semantic.Semantic { |
| 203 | +func newSemantic(logger *log.Log, upgradeVersionCmd *flag.FlagSet, gitHost, groupName, projectName, username, password *string, upgradePyFile *bool, branchName *string) *semantic.Semantic { |
184 | 204 |
|
185 | 205 | validateIncomingParams(logger, upgradeVersionCmd, gitHost, groupName, projectName, username, password, upgradePyFile)
|
186 | 206 |
|
187 | 207 | timer := time.New(logger)
|
188 | 208 | repositoryRootPath := fmt.Sprintf("%s/%s", homePath, *projectName)
|
189 | 209 |
|
190 | 210 | url := fmt.Sprintf("https://%s:%s@%s/%s/%s.git", *username, *password, *gitHost, *groupName, *projectName)
|
191 |
| - repoVersionControl, err := git.New(logger, timer.PrintElapsedTime, url, *username, *password, repositoryRootPath) |
| 211 | + repoVersionControl, err := git.New(logger, timer.PrintElapsedTime, url, *username, *password, repositoryRootPath, *branchName) |
192 | 212 | if err != nil {
|
193 | 213 | logger.Fatal(err.Error())
|
194 | 214 | }
|
195 | 215 |
|
196 |
| - filesVersionControl := files.New(logger, timer.PrintElapsedTime, *gitHost, repositoryRootPath, *groupName, *projectName) |
| 216 | + commitTypeManager := committype.New(logger) |
| 217 | + commitMessageManager := commitmessage.New(logger, commitTypeManager) |
| 218 | + |
| 219 | + filesVersionControl := files.New(logger, timer.PrintElapsedTime, *gitHost, repositoryRootPath, *groupName, *projectName, commitMessageManager) |
197 | 220 |
|
198 |
| - versionControl := v.NewVersionControl(logger, timer.PrintElapsedTime) |
| 221 | + versionControl := v.NewVersionControl(logger, timer.PrintElapsedTime, commitTypeManager) |
199 | 222 |
|
200 |
| - return semantic.New(logger, repositoryRootPath, addFilesToUpgradeList(upgradePyFile, repositoryRootPath), repoVersionControl, filesVersionControl, versionControl) |
| 223 | + return semantic.New(logger, repositoryRootPath, addFilesToUpgradeList(upgradePyFile, repositoryRootPath), repoVersionControl, filesVersionControl, versionControl, commitMessageManager, commitTypeManager) |
201 | 224 | }
|
0 commit comments