Example #1
0
        /// <summary>
        /// Deletes the worklog with the given id and updates the remaining estimate field on the isssue
        /// </summary>
        public void DeleteWorklog(Worklog worklog, WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate, string newEstimate = null)
        {
            if (String.IsNullOrEmpty(_originalIssue.key))
            {
                throw new InvalidOperationException("Unable to delete worklog from issue, issue has not been saved to server.");
            }

            Jira.WithToken((token, client) =>
            {
                switch (worklogStrategy)
                {
                case WorklogStrategy.AutoAdjustRemainingEstimate:
                    client.DeleteWorklogAndAutoAdjustRemainingEstimate(token, this._originalIssue.key, worklog.Id);
                    break;

                case WorklogStrategy.RetainRemainingEstimate:
                    client.DeleteWorklogAndRetainRemainingEstimate(token, this._originalIssue.key, worklog.Id);
                    break;

                case WorklogStrategy.NewRemainingEstimate:
                    client.DeleteWorklogWithNewRemainingEstimate(token, this._originalIssue.key, worklog.Id, newEstimate);
                    break;
                }
            });
        }
Example #2
0
        /// <summary>
        ///  Adds a worklog to this issue.
        /// </summary>
        /// <param name="worklog">The worklog instance to add</param>
        /// <param name="worklogStrategy">How to handle the remaining estimate, defaults to AutoAdjustRemainingEstimate</param>
        /// <param name="newEstimate">New estimate (only used if worklogStrategy set to NewRemainingEstimate)</param>
        /// <returns>Worklog as constructed by server</returns>
        public Worklog AddWorklog(Worklog worklog,
                                  WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate,
                                  string newEstimate = null)
        {
            if (String.IsNullOrEmpty(_originalIssue.key))
            {
                throw new InvalidOperationException("Unable to add worklog to issue, issue has not been saved to server.");
            }

            RemoteWorklog remoteWorklog = worklog.ToRemote();

            _jira.WithToken(token =>
            {
                switch (worklogStrategy)
                {
                case WorklogStrategy.RetainRemainingEstimate:
                    remoteWorklog = _jira.RemoteService.AddWorklogAndRetainRemainingEstimate(token, _originalIssue.key, remoteWorklog);
                    break;

                case WorklogStrategy.NewRemainingEstimate:
                    remoteWorklog = _jira.RemoteService.AddWorklogWithNewRemainingEstimate(token, _originalIssue.key, remoteWorklog, newEstimate);
                    break;

                default:
                    remoteWorklog = _jira.RemoteService.AddWorklogAndAutoAdjustRemainingEstimate(token, _originalIssue.key, remoteWorklog);
                    break;
                }
            });

            return(new Worklog(remoteWorklog));
        }
Example #3
0
 /// <summary>
 ///  Adds a worklog to this issue.
 /// </summary>
 /// <param name="timespent">Specifies a time duration in JIRA duration format, representing the time spent working on the worklog</param>
 /// <param name="worklogStrategy">How to handle the remaining estimate, defaults to AutoAdjustRemainingEstimate</param>
 /// <param name="newEstimate">New estimate (only used if worklogStrategy set to NewRemainingEstimate)</param>
 /// <returns>Worklog as constructed by server</returns>
 public Task <Worklog> AddWorklogAsync(string timespent,
                                       WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate,
                                       string newEstimate      = null,
                                       CancellationToken token = default(CancellationToken))
 {
     // todo: Use the CancellationToken Parameter
     return(AddWorklogAsync(new Worklog(timespent, DateTime.Now), worklogStrategy, newEstimate));
 }
Example #4
0
        /// <summary>
        /// Deletes the given worklog from the issue and updates the remaining estimate field.
        /// </summary>
        /// <param name="worklog">The worklog to remove.</param>
        /// <param name="worklogStrategy">How to handle the remaining estimate, defaults to AutoAdjustRemainingEstimate.</param>
        /// <param name="newEstimate">New estimate (only used if worklogStrategy set to NewRemainingEstimate)</param>
        /// <param name="token">Cancellation token for this operation.</param>
        public Task DeleteWorklogAsync(Worklog worklog, WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate, string newEstimate = null, CancellationToken token = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(_originalIssue.key))
            {
                throw new InvalidOperationException("Unable to delete worklog from issue, issue has not been saved to server.");
            }

            return(_jira.Issues.DeleteWorklogAsync(_originalIssue.key, worklog.Id, worklogStrategy, newEstimate, token));
        }
Example #5
0
        public Task DeleteWorklogAsync(string issueKey, string worklogId, WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate, string newEstimate = null, CancellationToken token = default(CancellationToken))
        {
            string queryString = null;

            if (worklogStrategy == WorklogStrategy.RetainRemainingEstimate)
            {
                queryString = "adjustEstimate=leave";
            }
            else if (worklogStrategy == WorklogStrategy.NewRemainingEstimate)
            {
                queryString = "adjustEstimate=new&newEstimate=" + Uri.EscapeDataString(newEstimate);
            }

            var resource = String.Format("rest/api/2/issue/{0}/worklog/{1}?{2}", issueKey, worklogId, queryString);

            return(_jira.RestClient.ExecuteRequestAsync(Method.DELETE, resource, null, token));
        }
Example #6
0
        public Task DeleteWorklogAsync(string issueKey, string worklogId, WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate, string newEstimate = null, CancellationToken token = default(CancellationToken))
        {
            string queryString     = null;
            var    queryParameters = new Dictionary <string, string>();

            if (worklogStrategy == WorklogStrategy.RetainRemainingEstimate)
            {
                queryParameters.Add("adjustEstimate", "leave");
            }
            else if (worklogStrategy == WorklogStrategy.NewRemainingEstimate)
            {
                queryParameters.Add("adjustEstimate", "new");
                queryParameters.Add("newEstimate", Uri.EscapeDataString(newEstimate));
            }

            var resource = String.Format("rest/api/latest/issue/{0}/worklog/{1}", issueKey, worklogId);

            return(_jira.RestClient.ExecuteRequestAsync(Method.DELETE, resource, queryParameters, token));
        }
Example #7
0
        public async Task <Worklog> AddWorklogAsync(string issueKey, Worklog worklog, WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate, string newEstimate = null, CancellationToken token = default(CancellationToken))
        {
            var    remoteWorklog = worklog.ToRemote();
            string queryString   = null;

            if (worklogStrategy == WorklogStrategy.RetainRemainingEstimate)
            {
                queryString = "adjustEstimate=leave";
            }
            else if (worklogStrategy == WorklogStrategy.NewRemainingEstimate)
            {
                queryString = "adjustEstimate=new&newEstimate=" + Uri.EscapeDataString(newEstimate);
            }

            var resource      = String.Format("rest/api/2/issue/{0}/worklog?{1}", issueKey, queryString);
            var serverWorklog = await _jira.RestClient.ExecuteRequestAsync <RemoteWorklog>(Method.POST, resource, remoteWorklog, token).ConfigureAwait(false);

            return(new Worklog(serverWorklog));
        }
Example #8
0
 /// <summary>
 ///  Adds a worklog to this issue.
 /// </summary>
 /// <param name="timespent">Specifies a time duration in JIRA duration format, representing the time spent working on the worklog</param>
 /// <param name="worklogStrategy">How to handle the remaining estimate, defaults to AutoAdjustRemainingEstimate</param>
 /// <param name="newEstimate">New estimate (only used if worklogStrategy set to NewRemainingEstimate)</param>
 /// <returns>Worklog as constructed by server</returns>
 public Worklog AddWorklog(string timespent,
                           WorklogStrategy worklogStrategy = WorklogStrategy.AutoAdjustRemainingEstimate,
                           string newEstimate = null)
 {
     return(AddWorklog(new Worklog(timespent, DateTime.Now), worklogStrategy, newEstimate));
 }
Example #9
0
        public void LogTime(Issue jiraIssue, DateTime exportTimeStamp, TimeSpan exportTime, WorklogStrategy strategy, string comment = "", TimeSpan?remainingTime = null)
        {
            var wasClosed = TryReopenJira(jiraIssue);

            if (string.IsNullOrWhiteSpace(comment))
            {
                comment = "No Comment Entered";
            }
            comment = "Gallifrey: " + comment;

            var    worklog   = new Worklog(string.Format("{0}h {1}m", exportTime.Hours, exportTime.Minutes), DateTime.SpecifyKind(exportTimeStamp, DateTimeKind.Local), comment);
            string remaining = null;

            if (remainingTime.HasValue)
            {
                remaining = string.Format("{0}h {1}m", exportTime.Hours, exportTime.Minutes);
            }
            try
            {
                jiraIssue.AddWorklog(worklog, strategy, remaining);
            }
            catch (Exception ex)
            {
                throw new WorkLogException("Error logging work", ex);
            }


            if (wasClosed)
            {
                try
                {
                    ReCloseJira(jiraIssue);
                }
                catch (Exception ex)
                {
                    throw new StateChangedException("Time Logged, but state is now open", ex);
                }
            }
        }
        public void LogTime(Issue jiraIssue, DateTime exportTimeStamp, TimeSpan exportTime, WorklogStrategy strategy, string comment = "", TimeSpan? remainingTime = null)
        {
            var wasClosed = TryReopenJira(jiraIssue);

            if (string.IsNullOrWhiteSpace(comment)) comment = "No Comment Entered";
            comment = "Gallifrey: " + comment;

            var worklog = new Worklog(string.Format("{0}h {1}m", exportTime.Hours, exportTime.Minutes), DateTime.SpecifyKind(exportTimeStamp, DateTimeKind.Local), comment);
            string remaining = null;
            if (remainingTime.HasValue)
            {
                remaining = string.Format("{0}h {1}m", exportTime.Hours, exportTime.Minutes);
            }
            try
            {
                jiraIssue.AddWorklog(worklog, strategy, remaining);
            }
            catch (Exception ex)
            {
                throw new WorkLogException("Error logging work", ex);
            }

            if (wasClosed)
            {
                try
                {
                    ReCloseJira(jiraIssue);
                }
                catch (Exception ex)
                {
                    throw new StateChangedException("Time Logged, but state is now open", ex);
                }
            }
        }