Exemple #1
0
        public static int PerformCommit(string commitMessage, bool addUntracked, bool stageTracked, bool fullCommit, bool amend)
        {
            var gitHelper = new GitHelper();

            if (!gitHelper.HasRepo)
            {
                SpectreHelper.WriteError("There is no repository");
                return(1);
            }

            var response = CommitCommandUtils.Commit(gitHelper, addUntracked, stageTracked,
                                                     fullCommit, commitMessage, amend);

            if (!response.Success)
            {
                SpectreHelper.WriteError(response.Message);
                return(1);
            }

            if (amend)
            {
                SpectreHelper.WriteSuccess($"{response.Message}\nCommit amend made successfully.");
                return(0);
            }

            SpectreHelper.WriteSuccess($"{response.Message}\nCommit made successfully.");
            return(0);
        }
Exemple #2
0
        public override int Execute(CommandContext context)
        {
            var gitHelper = new GitHelper();

            if (!gitHelper.HasRepo)
            {
                SpectreHelper.WriteError("There is no repository");
                return(1);
            }

            var flowHelper = new Modules.Flow(gitHelper);

            var response = flowHelper.Init();

            if (!response.Success)
            {
                SpectreHelper.WriteError(response.Message);
                return(1);
            }

            if (response.GitReponse is not EnumGitResponse.NONE)
            {
                SpectreHelper.WriteWarning(response.Message);
                return(0);
            }

            SpectreHelper.WriteSuccess(response.Message);
            return(0);
        }
Exemple #3
0
        public override int Execute(CommandContext context)
        {
            var          gitHelper  = new GitHelper();
            var          flowHelper = new Modules.Flow(gitHelper);
            FlowResponse response;

            var createResponse = gitHelper.CreateRepository();

            if (!createResponse.Success)
            {
                response = new FlowResponse(createResponse.Success, EnumFlowResponse.GIT_ERROR,
                                            createResponse.Response, createResponse.Message);
            }
            else
            {
                response = flowHelper.Init();
            }

            if (!response.Success)
            {
                SpectreHelper.WriteError(response.Message);
                return(1);
            }

            if (response.GitReponse is not EnumGitResponse.NONE)
            {
                SpectreHelper.WriteWarning(response.Message);
                return(0);
            }

            SpectreHelper.WriteSuccess(response.Message);
            return(0);
        }
        public override int Execute(CommandContext context, ChangelogGenerateOptions options)
        {
            var changelog = ChangelogGenerator.GenerateSince(options.StartDate);

            if (string.IsNullOrWhiteSpace(changelog))
            {
                SpectreHelper.WriteError("There were no commits to generate the changelog from.");
                return(1);
            }

            SpectreHelper.WriteInfo(changelog);
            return(0);
        }
Exemple #5
0
        public override int Execute(CommandContext context)
        {
            var subject = AnsiConsole.Ask <string>("Enter the commit subject:");
            var message = CommitCommandUtils.GenerateCommitMessage(true, subject);

            if (string.IsNullOrWhiteSpace(message))
            {
                SpectreHelper.WriteError("There was an error generating the commit message.");
                return(1);
            }

            SpectreHelper.WriteWrappedHeader("Your commit message:");
            SpectreHelper.WriteInfo(message);
            return(0);
        }
Exemple #6
0
        public override int Execute(CommandContext context, FlowPublishSettings options)
        {
            var gitHelper = new GitHelper();

            if (!gitHelper.HasRepo)
            {
                SpectreHelper.WriteError("There is no repository");
                return(1);
            }

            if (string.IsNullOrWhiteSpace(options.BranchName))
            {
                options.BranchName = AnsiConsole.Prompt(
                    new SelectionPrompt <string>()
                    .Title("Please select a branch:")
                    .PageSize(10)
                    .MoreChoicesText("(Move up and down to reveal more branches)")
                    .AddChoices(gitHelper.LocalBranches));
            }

            var flowHelper = new Modules.Flow(gitHelper);

            var response = flowHelper.Publish(options.BranchName);

            if (!response.Success)
            {
                SpectreHelper.WriteError(response.Message);
                return(1);
            }

            if (response.GitReponse is not EnumGitResponse.NONE)
            {
                SpectreHelper.WriteWarning(response.Message);
                return(0);
            }

            SpectreHelper.WriteSuccess(response.Message);
            return(0);
        }
Exemple #7
0
        public override int Execute(CommandContext context, FlowStartSettings options)
        {
            var gitHelper  = new GitHelper();
            var flowHelper = new Modules.Flow(gitHelper);

            if (!gitHelper.HasRepo)
            {
                SpectreHelper.WriteError("There is no repository");
                return(1);
            }

            var type = AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title("Select the branch type:")
                .PageSize(10)
                .MoreChoicesText("(Move up and down to reveal more branch types)")
                .AddChoices(Constants.ValidWorkingBranchTypeWithDescriptions))
                       .Split(':', StringSplitOptions.TrimEntries)[0];

            var response = flowHelper.Start(options.BranchName, type);

            if (!response.Success)
            {
                SpectreHelper.WriteError(response.Message);
                return(1);
            }

            if (response.GitReponse is not EnumGitResponse.NONE)
            {
                SpectreHelper.WriteWarning(response.Message);
                return(0);
            }

            SpectreHelper.WriteSuccess(response.Message);
            return(0);
        }
Exemple #8
0
        public static string Generate(IEnumerable <string> commitMessages)
        {
            var messageList = commitMessages?.ToList();

            if (messageList is null || messageList.Count == 0)
            {
                SpectreHelper.WriteError("No commits were provided.");
                return(null);
            }

            var lintedMessages = messageList.Select(message => new CommitMessageLinter(message)).ToList();

            var added = lintedMessages.Where(message => message.IsValid && message.Tag is "feature")
                        .Select(linter => linter.Subject).ToList();

            var changed = lintedMessages.Where(message => message.IsValid && message.Tag is "change" or "refactor")
                          .Select(linter => linter.Subject).ToList();

            var breakingChanges = lintedMessages.Where(message => message.IsValid && message.HasFlags && message.Flags.Contains("!!!"))
                                  .Select(linter => linter.Subject).ToList();

            var fixes = lintedMessages.Where(message => message.IsValid && message.Tag is "fix")
                        .Select(linter => linter.Subject).ToList();

            var updated = lintedMessages.Where(message => message.IsValid && message.Tag is "chore").
                          Select(linter => linter.Subject).ToList();

            var deprecated = lintedMessages.Where(message => message.IsValid && message.HasFlags && message.Flags.Contains("dpc"))
                             .Select(linter => linter.Subject).ToList();

            var removed = lintedMessages.Where(message => message.IsValid && message.HasFlags && message.Flags.Contains("rm"))
                          .Select(linter => linter.Subject).ToList();

            var changelog = string.Empty;

            if (added.Count != 0)
            {
                changelog += $"### Added\n{string.Join('\n', added)}\n\n";
            }

            if (changed.Count != 0)
            {
                changelog += $"### Changed\n{string.Join('\n', changed)}\n\n";
            }

            if (breakingChanges.Count != 0)
            {
                changelog += $"### Breaking Changes\n{string.Join('\n', breakingChanges)}\n\n";
            }

            if (fixes.Count != 0)
            {
                changelog += $"### Fixed\n{string.Join('\n', fixes)}\n\n";
            }

            if (updated.Count != 0)
            {
                changelog += $"### Chores\n{string.Join('\n', updated)}\n\n";
            }

            if (deprecated.Count != 0)
            {
                changelog += $"### Deprecated\n{string.Join('\n', deprecated)}\n\n";
            }

            if (removed.Count != 0)
            {
                changelog += $"### Removed\n{string.Join('\n', removed)}\n\n";
            }

            return(changelog.TrimEnd('\n'));
        }