コード例 #1
0
ファイル: JiraClient.cs プロジェクト: punker76/Gallifrey
        public JiraClient(string baseUrl, string username, string password, bool useTempo, string tempoToken)
        {
            var url = baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/api/2";

            jiraClient = SimpleRestClient.WithBasicAuthentication(url, username, password, GetErrorMessages);

            try
            {
                myUser = GetCurrentUser();
            }
            catch (Exception e)
            {
                throw new ConnectionError(ConnectionError.Type.Jira, "Error connecting to jira", e);
            }

            if (useTempo)
            {
                tempoClient = SimpleRestClient.WithBearerAuthentication("https://api.tempo.io/core/3", tempoToken, null);

                try
                {
                    var queryDate = DateTime.UtcNow;
                    tempoClient.Get <TempoWorkLogSearch>(HttpStatusCode.OK, $"worklogs/user/{myUser.accountId}?from={queryDate:yyyy-MM-dd}&to={queryDate:yyyy-MM-dd}");
                }
                catch (Exception e)
                {
                    throw new ConnectionError(ConnectionError.Type.Tempo, "Error connecting to tempo", e);
                }
            }
            else
            {
                tempoClient = null;
            }
        }
コード例 #2
0
        public JiraRestClient(string baseUrl, string username, string password, bool useTempo)
        {
            var url = baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/";

            restClient = new SimpleRestClient(url, username, password, GetErrorMessages);
            myUser     = GetCurrentUser();
            if (useTempo)
            {
                try
                {
                    //NOTE THIS IS NOT THE RIGHT TYPE, BUT NOT EXPECTING VALID DATA ANYWAY
                    restClient.Get <List <string> >(HttpStatusCode.OK, "tempo-timesheets/3/worklogs?dateFrom=1990-01-01&dateTo=1990-01-02");
                    HasTempo = true;
                }
                catch (Exception)
                {
                    HasTempo = false;
                }
            }
            else
            {
                HasTempo = false;
            }
        }
コード例 #3
0
 public User GetCurrentUser()
 {
     return(restClient.Get <User>(HttpStatusCode.OK, "api/2/myself"));
 }
コード例 #4
0
ファイル: JiraClient.cs プロジェクト: punker76/Gallifrey
 public User GetCurrentUser()
 {
     return(jiraClient.Get <User>(HttpStatusCode.OK, "myself"));
 }
コード例 #5
0
ファイル: JiraClient.cs プロジェクト: punker76/Gallifrey
        public IEnumerable <StandardWorkLog> GetWorkLoggedForDatesFilteredIssues(List <DateTime> queryDates, List <string> issueRefs)
        {
            var workLogs = new List <StandardWorkLog>();

            if (tempoClient != null)
            {
                foreach (var queryDate in queryDates)
                {
                    var logs = tempoClient.Get <TempoWorkLogSearch>(HttpStatusCode.OK, $"worklogs/user/{myUser.accountId}?from={queryDate:yyyy-MM-dd}&to={queryDate:yyyy-MM-dd}&limit=200");

                    foreach (var tempoWorkLog in logs.results.Where(x => x.author.accountId.Equals(myUser.accountId, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        if (issueRefs == null || issueRefs.Any(x => string.Equals(x, tempoWorkLog.issue.key, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            var workLogReturn = workLogs.FirstOrDefault(x => x.JiraRef == tempoWorkLog.issue.key && x.LoggedDate.Date == queryDate.Date);
                            if (workLogReturn != null)
                            {
                                workLogReturn.AddTime(tempoWorkLog.timeSpentSeconds);
                            }
                            else
                            {
                                workLogs.Add(new StandardWorkLog(tempoWorkLog.issue.key, queryDate.Date, tempoWorkLog.timeSpentSeconds));
                            }
                        }
                    }
                }
            }
            else
            {
                var workLogCache = new Dictionary <string, WorkLogs>();
                foreach (var queryDate in queryDates)
                {
                    var issuesExportedTo = GetIssuesFromJql($"worklogAuthor = currentUser() and worklogDate = {queryDate:yyyy-MM-dd}");
                    foreach (var issue in issuesExportedTo)
                    {
                        if (issueRefs == null || issueRefs.Any(x => string.Equals(x, issue.key, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            WorkLogs logs;
                            if (workLogCache.ContainsKey(issue.key))
                            {
                                logs = workLogCache[issue.key];
                            }
                            else
                            {
                                logs = jiraClient.Get(HttpStatusCode.OK, $"issue/{issue.key}/worklog", customDeserialize: s => FilterWorklogsToUser(s, myUser));
                                workLogCache.Add(issue.key, logs);
                            }

                            foreach (var workLog in logs.worklogs.Where(x => x.started.Date == queryDate.Date))
                            {
                                var workLogReturn = workLogs.FirstOrDefault(x => x.JiraRef == issue.key && x.LoggedDate.Date == queryDate.Date);
                                if (workLogReturn != null)
                                {
                                    workLogReturn.AddTime(workLog.timeSpentSeconds);
                                }
                                else
                                {
                                    workLogs.Add(new StandardWorkLog(issue.key, queryDate.Date, workLog.timeSpentSeconds));
                                }
                            }
                        }
                    }
                }
            }

            return(workLogs);
        }