Exemplo n.º 1
0
        public override void DeployRelease(JiraContext context)
        {
            var releaseNumber = context.FixForVersion;

            if (string.IsNullOrEmpty(releaseNumber))
            {
                throw new ArgumentNullException("releaseNumber");
            }

            if (string.IsNullOrEmpty(context.Project.Key))
            {
                throw new InvalidOperationException("Application must be specified in category ID filter to close a release.");
            }

            // Ensure version exists.
            var versions = this.Service.getVersions(this.Token, context.Project.Key);
            var version  = Array.Find(versions, v => releaseNumber.Equals((v.name ?? "").Trim(), StringComparison.OrdinalIgnoreCase));

            if (version == null)
            {
                throw new InvalidOperationException("Version " + releaseNumber + " does not exist.");
            }

            // If version is already released, do nothing.
            if (version.released)
            {
                return;
            }

            // Otherwise release it.
            version.released    = true;
            version.releaseDate = DateTime.Now;
            this.Service.releaseVersion(this.Token, context.Project.Key, version);
        }
Exemplo n.º 2
0
        public override IIssueTrackerIssue CreateIssue(JiraContext context, string title, string description, string type)
        {
            var versions = this.Service.getVersions(this.Token, context.Project.Key)
                           .Where(v => string.Equals(v.name, context.FixForVersion, StringComparison.OrdinalIgnoreCase))
                           .ToArray();

            if (context.FixForVersion != null && versions.Length == 0)
            {
                this.log.LogWarning($"Could not set Fix For version to '{context.FixForVersion}' because it was not found in JIRA for project key '{context.Project.Key}'.");
            }

            var issue = this.Service.createIssue(
                this.Token,
                new RemoteIssue
            {
                project     = context.Project.Key,
                summary     = title,
                description = description,
                type        = type,
                fixVersions = versions
            }
                );

            return(new JiraIssue(issue, this.IssueStatuses, this.serverUrl));
        }
Exemplo n.º 3
0
        public override void CreateRelease(JiraContext context)
        {
            var releaseNumber = context.FixForVersion;

            if (string.IsNullOrEmpty(releaseNumber))
            {
                throw new ArgumentNullException("releaseNumber");
            }

            if (string.IsNullOrEmpty(context.Project.Key))
            {
                throw new InvalidOperationException("Application must be specified in category ID filter to create a release.");
            }

            // If version is already created, do nothing.
            var versions = this.Service.getVersions(this.Token, context.Project.Key);

            if (Array.Find(versions, v => releaseNumber.Equals((v.name ?? "").Trim(), StringComparison.OrdinalIgnoreCase)) != null)
            {
                return;
            }

            // Otherwise add it.
            this.Service.addVersion(this.Token, context.Project.Key, new RemoteVersion {
                name = releaseNumber
            });
        }
Exemplo n.º 4
0
        public override IEnumerable <IIssueTrackerIssue> EnumerateIssues(JiraContext context)
        {
            var version = this.Service.getVersions(this.Token, context.Project.Key)
                          .FirstOrDefault(v => string.Equals(v.name, context.FixForVersion, StringComparison.OrdinalIgnoreCase));

            if (version == null)
            {
                return(Enumerable.Empty <IIssueTrackerIssue>());
            }

            var projectFilter = string.Empty;

            if (!string.IsNullOrEmpty(context.Project.Key))
            {
                projectFilter = " and project = \"" + context.Project.Key + "\"";
            }

            var issues = this.Service.getIssuesFromJqlSearch(
                this.Token,
                string.Format("fixVersion = \"{0}\" {1}", context.FixForVersion, projectFilter),
                int.MaxValue
                );

            if (issues.Length == 0)
            {
                return(Enumerable.Empty <IIssueTrackerIssue>());
            }

            var baseUrl = this.serverUrl.TrimEnd('/');

            return(from i in issues
                   select new JiraIssue(i, this.IssueStatuses, baseUrl));
        }
Exemplo n.º 5
0
        public override void AddComment(JiraContext context, string issueId, string commentText)
        {
            var comment = new RemoteComment {
                body = commentText
            };

            this.Service.addComment(this.Token, issueId, comment);
        }
Exemplo n.º 6
0
        public override void CreateRelease(JiraContext context)
        {
            var version = this.TryGetVersion(context);

            if (version != null)
            {
                return;
            }

            this.restClient.CreateVersion(context.Project.Key, context.FixForVersion);
        }
Exemplo n.º 7
0
        public override IEnumerable <IIssueTrackerIssue> EnumerateIssues(JiraContext context)
        {
            var version = this.TryGetVersion(context);

            if (version == null)
            {
                return(Enumerable.Empty <IIssueTrackerIssue>());
            }

            return(this.restClient.GetIssues(context.Project.Key, version.Name));
        }
Exemplo n.º 8
0
 public void CloseAllIssues(JiraContext context)
 {
     foreach (var issue in this.EnumerateIssues(context))
     {
         if (issue.IsClosed)
         {
             this.log.LogDebug($"{issue.Id} is already closed, skipping...");
             continue;
         }
         this.CloseIssue(context, issue.Id);
     }
 }
Exemplo n.º 9
0
        private ProjectVersion TryGetVersion(JiraContext context)
        {
            if (string.IsNullOrEmpty(context.FixForVersion))
            {
                throw new ArgumentException(nameof(context.FixForVersion));
            }
            if (string.IsNullOrEmpty(context.Project.Key))
            {
                throw new InvalidOperationException("Application must be specified in category ID filter to create a release.");
            }

            return(this.restClient.GetVersions(context.Project.Key).FirstOrDefault(v => v.Name == context.FixForVersion));
        }
Exemplo n.º 10
0
        public override void CloseIssue(JiraContext context, string issueId)
        {
            var availableActions = this.Service.getAvailableActions(this.Token, issueId);
            var closeAction      = availableActions
                                   .FirstOrDefault(a => string.Equals(a.name, "Close Issue", StringComparison.OrdinalIgnoreCase));

            this.Service.progressWorkflowAction(
                this.Token,
                issueId,
                closeAction.id,
                new RemoteFieldValue[0]
                );
        }
Exemplo n.º 11
0
        public override IEnumerable <Transition> GetTransitions(JiraContext context)
        {
            var issue = this.EnumerateIssues(context).LastOrDefault();

            if (issue == null)
            {
                return(Enumerable.Empty <Transition>());
            }

            var transitions = this.restClient.GetTransitions(issue.Id);

            return(transitions);
        }
Exemplo n.º 12
0
        public override void CloseIssue(JiraContext context, string issueId)
        {
            var validTransitions = this.restClient.GetTransitions(issueId);
            var closeTransition  = validTransitions.FirstOrDefault(t => t.Name.Equals(context.ClosedState, StringComparison.OrdinalIgnoreCase));

            if (closeTransition == null)
            {
                this.log.LogError($"Cannot close issue {issueId} because the issue cannot be transitioned to the configured closed state on the provider: {context.ClosedState}");
            }
            else
            {
                this.restClient.TransitionIssue(issueId, closeTransition.Id);
            }
        }
Exemplo n.º 13
0
        public override void DeployRelease(JiraContext context)
        {
            var version = this.TryGetVersion(context);

            if (version == null)
            {
                throw new InvalidOperationException("Version " + context.FixForVersion + " does not exist.");
            }

            if (version.Released)
            {
                return;
            }

            this.restClient.ReleaseVersion(context.Project.Key, version.Id);
        }
Exemplo n.º 14
0
        public override void TransitionIssue(JiraContext context, string issueId, string issueStatus)
        {
            if (string.IsNullOrWhiteSpace(issueStatus))
            {
                throw new ArgumentException("The status being applied must contain text.", nameof(issueStatus));
            }

            var issue = this.restClient.GetIssue(issueId);

            if (issue.Status == issueStatus)
            {
                this.log.LogDebug($"{issue.Id} is already in the {issueStatus} status.");
                return;
            }

            this.ChangeIssueStatusInternal(issue, issueStatus);
        }
Exemplo n.º 15
0
        public override void TransitionIssuesInStatus(JiraContext context, string fromStatus, string toStatus)
        {
            if (string.IsNullOrWhiteSpace(toStatus))
            {
                throw new ArgumentException("The status being applied must contain text.", nameof(toStatus));
            }

            foreach (var issue in this.EnumerateIssues(context))
            {
                if (!string.IsNullOrEmpty(fromStatus) && !string.Equals(issue.Status, fromStatus, StringComparison.OrdinalIgnoreCase))
                {
                    this.log.LogDebug($"{issue.Id} ({issue.Status}) is not in the {fromStatus} status, and will not be changed.");
                    continue;
                }

                this.ChangeIssueStatusInternal(issue, toStatus);
            }
        }
Exemplo n.º 16
0
        public override void TransitionIssuesInStatus(JiraContext context, string fromStatus, string toStatus)
        {
            // verify status name is text
            toStatus = (toStatus ?? "").Trim();
            if (string.IsNullOrEmpty(toStatus) || toStatus.Length < 2)
            {
                throw new ArgumentException("The status being applied must contain text and be at least 2 characters long", "newStatus");
            }

            foreach (var jiraIssue in this.EnumerateIssues(context))
            {
                if (!string.IsNullOrEmpty(fromStatus) && !string.Equals(jiraIssue.Status, fromStatus, StringComparison.OrdinalIgnoreCase))
                {
                    this.log.LogDebug($"{jiraIssue.Id} ({jiraIssue.Status}) is not in the {fromStatus} status, and will not be changed.");
                    continue;
                }

                this.ChangeIssueStatusInternal((JiraIssue)jiraIssue, toStatus);
            }
        }
Exemplo n.º 17
0
        public override void TransitionIssue(JiraContext context, string issueId, string issueStatus)
        {
            // verify status name is text
            issueStatus = (issueStatus ?? "").Trim();
            if (string.IsNullOrEmpty(issueStatus) || issueStatus.Length < 2)
            {
                throw new ArgumentException("The status being applied must contain text and be at least 2 characters long", "newStatus");
            }

            // return if the issue is already set to the new status
            var issue     = this.Service.getIssue(this.Token, issueId);
            var jiraIssue = new JiraIssue(issue, this.IssueStatuses, this.serverUrl);

            if (jiraIssue.Status == issueStatus)
            {
                this.log.LogDebug($"{jiraIssue.Id} is already in the {issueStatus} status.");
                return;
            }

            this.ChangeIssueStatusInternal(jiraIssue, issueStatus);
        }
Exemplo n.º 18
0
 public override Task <IEnumerable <IIssueTrackerIssue> > EnumerateIssuesAsync(JiraContext context)
 {
     return(this.restClient.GetIssuesAsync(context.GetJql()));
 }
Exemplo n.º 19
0
 public abstract void TransitionIssue(JiraContext context, string issueId, string issueStatus);
Exemplo n.º 20
0
 public abstract IIssueTrackerIssue CreateIssue(JiraContext context, string title, string description, string type);
Exemplo n.º 21
0
 public abstract void CloseIssue(JiraContext context, string issueId);
Exemplo n.º 22
0
 public abstract void CreateRelease(JiraContext context);
Exemplo n.º 23
0
 public override IIssueTrackerIssue CreateIssue(JiraContext context, string title, string description, string type)
 {
     return(this.restClient.CreateIssue(context.Project.Key, title, description, type, context.FixForVersion));
 }
Exemplo n.º 24
0
 public abstract void AddComment(JiraContext context, string issueId, string commentText);
Exemplo n.º 25
0
 public override void AddComment(JiraContext context, string issueId, string commentText)
 {
     this.restClient.AddComment(issueId, commentText);
 }
Exemplo n.º 26
0
 public abstract void TransitionIssuesInStatus(JiraContext context, string fromStatus, string toStatus);
Exemplo n.º 27
0
 public override IEnumerable <Transition> GetTransitions(JiraContext context)
 {
     return(Enumerable.Empty <Transition>());
 }
Exemplo n.º 28
0
 public abstract void DeployRelease(JiraContext context);
Exemplo n.º 29
0
        public override Task <IEnumerable <IIssueTrackerIssue> > EnumerateIssuesAsync(JiraContext context)
        {
            var issues = this.EnumerateIssues(context);

            return(Task.FromResult(issues));
        }
Exemplo n.º 30
0
 public abstract Task <IEnumerable <IIssueTrackerIssue> > EnumerateIssuesAsync(JiraContext context);