Example #1
0
        public override async Task <(string cloneLocation, Dictionary <string, string> outputValues, string errorMessage)> Clone()
        {
            var cloneLocation = CloneTaskConfig.CloneLocation ?? CloneTaskConfig.WorkingLocation;
            var repoConfig    = GetGitAutomationConfig(cloneLocation, CloneTaskConfig.Repository, AdditionalConfigs, CloneTaskConfig.IsPrivateRepository);

            if (_gitAutomation == null)
            {
                _gitAutomation = new GitAutomation(repoConfig, _gitHubUtils, Logger);
            }

            var error = await _gitAutomation.CreateRepositoryIfNotExists();

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            error = await _gitAutomation.Clone();

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            if (!string.IsNullOrEmpty(CloneTaskConfig.BaseBranch))
            {
                await _gitAutomation.CheckoutBranch(CloneTaskConfig.BaseBranch);
            }

            return(cloneLocation, null, "");
        }
Example #2
0
        public override async Task <(string remoteUrl, string pullRequestUrl, Dictionary <string, string> outputValues, string errorMessage)> Push()
        {
            var repoConfig = GetGitAutomationConfig(PushTaskConfig.SourceLocation ?? PushTaskConfig.WorkingLocation, PushTaskConfig.Repository, AdditionalConfigs);

            if (_gitAutomation == null)
            {
                _gitAutomation = new GitAutomation(repoConfig, _gitHubUtils, Logger);
            }

            string baseBranch    = PushTaskConfig.PullRequestTargetBranch ?? DefaultBaseBranch;
            string workingBranch = PushTaskConfig.Branch ?? (PushTaskConfig.CreatePullRequest ? DefaultWorkingBranch : DefaultBaseBranch);

            var error = await _gitAutomation.CreateRepositoryIfNotExists();

            if (!string.IsNullOrEmpty(error))
            {
                return("", "", null, error);
            }

            error = await _gitAutomation.Commit(baseBranch, workingBranch, PushTaskConfig.CommitMessage ?? DefaultCommitMessage, PushTaskConfig.Author ?? DefaultAuthor, PushTaskConfig.Email ?? DefaultEmail);

            if (!string.IsNullOrEmpty(error))
            {
                return("", "", null, error);
            }

            error = await _gitAutomation.Push(workingBranch);

            if (!string.IsNullOrEmpty(error))
            {
                return("", "", null, error);
            }

            Dictionary <string, string> outputValues = null;

            string pullRequestUrl = "";

            if (PushTaskConfig.CreatePullRequest)
            {
                var prNumber = await _gitAutomation.SubmitPullRequest(workingBranch, baseBranch);

                if (prNumber > 0)
                {
                    outputValues = new Dictionary <string, string>
                    {
                        { "PRNumber", prNumber.ToString() }
                    };

                    pullRequestUrl = $"{repoConfig.RemoteUrl.TrimEnd('/')}/pull/{prNumber}";
                }
            }

            return(repoConfig.RemoteUrl, pullRequestUrl, outputValues, "");
        }
Example #3
0
        public async override Task <string> DeleteRepository()
        {
            var repoConfig = GetGitAutomationConfig("", DeleteTaskConfig.Repository, AdditionalConfigs);

            if (_gitAutomation == null)
            {
                _gitAutomation = new GitAutomation(repoConfig, _gitHubUtils, Logger);
            }

            var error = await _gitAutomation.DeleteRepository();

            if (!string.IsNullOrEmpty(error))
            {
                return(error);
            }

            return("");
        }
Example #4
0
        public override async Task <(string remoteUrl, Dictionary <string, string> outputValues, string errorMessage)> Merge()
        {
            var repoConfig = GetGitAutomationConfig("", MergeTaskConfig.Repository, AdditionalConfigs);

            if (_gitAutomation == null)
            {
                _gitAutomation = new GitAutomation(repoConfig, _gitHubUtils, Logger);
            }

            var success = await _gitAutomation.MergePullRequest(PrNumber);

            if (!success)
            {
                return("", null, "Failed to merge pull request.");
            }

            return(MergeTaskConfig.Repository, null, "");
        }
Example #5
0
        public override async Task <(string repositoryLocation, Dictionary <string, string> outputValues, string errorMessage)> Pull()
        {
            var repositoryLocation = PullTaskConfig.RepositoryLocation ?? PullTaskConfig.WorkingLocation;
            var repoConfig         = GetGitAutomationConfig(repositoryLocation, PullTaskConfig.Repository, AdditionalConfigs, PullTaskConfig.IsPrivateRepository, ProjectMembers);

            if (_gitAutomation == null)
            {
                _gitAutomation = new GitAutomation(repoConfig, _gitHubUtils, Logger);
            }

            var error = await _gitAutomation.CreateRepositoryIfNotExists();

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            error = await _gitAutomation.CloneIfNotExistLocally();

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            if (!string.IsNullOrEmpty(PullTaskConfig.BaseBranch))
            {
                await _gitAutomation.CheckoutBranch(PullTaskConfig.BaseBranch);
            }
            else
            {
                await _gitAutomation.CheckoutBranch(DefaultBaseBranch);
            }

            error = await _gitAutomation.Pull(DefaultAuthor, DefaultEmail);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            return(repositoryLocation, null, "");
        }