示例#1
0
 private static void GenerateClassicalRequest(IIssueTrackerContext context, RestRequest request, string methodLocation)
 {
     var usernameAndPass = string.Format("{0}:{1}", context.Username, context.Password);
     var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(usernameAndPass));
     request.Resource = string.Format(methodLocation);
     request.AddHeader("Authorization", string.Format("Basic {0}", token));
 }
示例#2
0
        private static void GenerateClassicalRequest(IIssueTrackerContext context, RestRequest request, string methodLocation)
        {
            var usernameAndPass = string.Format("{0}:{1}", context.Username, context.Password);
            var token           = Convert.ToBase64String(Encoding.UTF8.GetBytes(usernameAndPass));

            request.Resource = string.Format(methodLocation);
            request.AddHeader("Authorization", string.Format("Basic {0}", token));
        }
示例#3
0
        public IEnumerable <OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset?since)
        {
            var youTrackContext = (YouTrackContext)context;

            var authenticationCookies = ConnectToYouTrack(context.Username, context.Password, context.Url);

            return(IssuesClosedSinceDate(
                       authenticationCookies,
                       youTrackContext.Filter,
                       context.Url,
                       context.ProjectId,
                       since));
        }
        public IEnumerable <OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset?since)
        {
            string organisation;
            string repository;

            GetRepository(out organisation, out repository);

            var gitHubClient  = _gitHubClientFactory();
            var forRepository = gitHubClient.Issue.GetForRepository(organisation, repository, new RepositoryIssueRequest
            {
                Filter = IssueFilter.All,
                Since  = since,
                State  = ItemState.Closed
            });

            var readOnlyList = forRepository.Result.Where(i => i.ClosedAt > since);

            var userCache = new Dictionary <string, User>();
            Func <User, string> getUserName = u =>
            {
                var login = u.Login;
                if (!userCache.ContainsKey(login))
                {
                    userCache.Add(login, string.IsNullOrEmpty(u.Name) ? gitHubClient.User.Get(login).Result : u);
                }

                var user = userCache[login];
                if (user != null)
                {
                    return(user.Name);
                }

                return(null);
            };

            return(readOnlyList.Select(i => new OnlineIssue("#" + i.Number.ToString(CultureInfo.InvariantCulture), i.ClosedAt.Value)
            {
                HtmlUrl = i.HtmlUrl,
                Title = i.Title,
                IssueType = i.PullRequest == null ? IssueType.Issue : IssueType.PullRequest,
                Labels = i.Labels.Select(l => l.Name).ToArray(),
                Contributors = i.PullRequest == null ? new GitReleaseNotes.Contributor[0] : new[]
                {
                    new GitReleaseNotes.Contributor(getUserName(i.User), i.User.Login, i.User.HtmlUrl)
                }
            }));
        }
示例#5
0
        public IEnumerable <OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset?since, string accountName, string repoSlug, bool oauth)
        {
            var baseUrl    = new Uri(ApiUrl, UriKind.Absolute);
            var restClient = new RestClient(baseUrl.AbsoluteUri);
            var issuesUrl  = string.Format("repositories/{0}/{1}/issues/", accountName, repoSlug);
            var request    = new RestRequest(issuesUrl);

            if (oauth)
            {
                GenerateOauthRequest(context, baseUrl, issuesUrl, request);
            }
            else
            {
                GenerateClassicalRequest(context, request, issuesUrl);
            }

            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Failed to query BitBucket: " + response.StatusDescription);
            }

            dynamic responseObject = JsonConvert.DeserializeObject <dynamic>(response.Content);

            var issues = new List <OnlineIssue>();

            foreach (var issue in responseObject.issues)
            {
                DateTimeOffset lastChange = DateTimeOffset.Parse(issue.utc_last_updated.ToString());
                if ((issue.status != IssueClosed && issue.status != IssueResolved) || lastChange <= since)
                {
                    continue;
                }
                string summary = issue.content;
                string id      = issue.local_id.ToString();
                string title   = issue.title;
                issues.Add(new OnlineIssue(id, lastChange)
                {
                    Title     = summary,
                    IssueType = IssueType.Issue,
                    HtmlUrl   = new Uri(baseUrl, string.Format("/repositories/{0}/{1}/issue/{2}/{3}", accountName, repoSlug, id, title))
                });
            }
            return(issues);
        }
示例#6
0
        public IEnumerable<OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset? since, string accountName, string repoSlug, bool oauth)
        {
            var baseUrl = new Uri(ApiUrl, UriKind.Absolute);
            var restClient = new RestClient(baseUrl.AbsoluteUri);
            var issuesUrl = string.Format("repositories/{0}/{1}/issues/", accountName, repoSlug);
            var request = new RestRequest(issuesUrl);
            if (oauth)
            {
                GenerateOauthRequest(context, baseUrl, issuesUrl, request);
            }
            else
            {
                GenerateClassicalRequest(context, request, issuesUrl);
            }

            var response = restClient.Execute(request);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Failed to query BitBucket: " + response.StatusDescription);
            }

            dynamic responseObject = JsonConvert.DeserializeObject<dynamic>(response.Content);
            
            var issues = new List<OnlineIssue>();
            foreach (var issue in responseObject.issues)
            {
                DateTimeOffset lastChange = DateTimeOffset.Parse(issue.utc_last_updated.ToString());
                if ((issue.status != IssueClosed && issue.status != IssueResolved) || lastChange <= since)
                {
                    continue;
                }
                string summary = issue.content;
                string id = issue.local_id.ToString();
                string title = issue.title;
                issues.Add(new OnlineIssue(id, lastChange)
                {
                    Title = summary,
                    IssueType = IssueType.Issue,
                    HtmlUrl = new Uri(baseUrl, string.Format("/repositories/{0}/{1}/issue/{2}/{3}", accountName, repoSlug, id, title))
                });
            }
            return issues;
        }
示例#7
0
        private static void GenerateOauthRequest(IIssueTrackerContext context, Uri baseUrl, string methodLocation, RestRequest request)
        {
            var consumerKey = context.Username;
            var consumerSecret = context.Password;
            var oAuth = new OAuthBase();
            var nonce = oAuth.GenerateNonce();
            var timeStamp = oAuth.GenerateTimeStamp();
            string normalizedUrl;
            string normalizedRequestParameters;
            var sig = oAuth.GenerateSignature(new Uri(baseUrl + methodLocation), consumerKey, consumerSecret, null, null, "GET", timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);

            request.Resource = string.Format(methodLocation);
            request.Method = Method.GET;
            request.AddParameter("oauth_consumer_key", consumerKey);
            request.AddParameter("oauth_nonce", nonce);
            request.AddParameter("oauth_timestamp", timeStamp);
            request.AddParameter("oauth_signature_method", "HMAC-SHA1");
            request.AddParameter("oauth_version", "1.0");
            request.AddParameter("oauth_signature", sig);
        }
示例#8
0
        private static void GenerateOauthRequest(IIssueTrackerContext context, Uri baseUrl, string methodLocation, RestRequest request)
        {
            var    consumerKey    = context.Username;
            var    consumerSecret = context.Password;
            var    oAuth          = new OAuthBase();
            var    nonce          = oAuth.GenerateNonce();
            var    timeStamp      = oAuth.GenerateTimeStamp();
            string normalizedUrl;
            string normalizedRequestParameters;
            var    sig = oAuth.GenerateSignature(new Uri(baseUrl + methodLocation), consumerKey, consumerSecret, null, null, "GET", timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);

            request.Resource = string.Format(methodLocation);
            request.Method   = Method.GET;
            request.AddParameter("oauth_consumer_key", consumerKey);
            request.AddParameter("oauth_nonce", nonce);
            request.AddParameter("oauth_timestamp", timeStamp);
            request.AddParameter("oauth_signature_method", "HMAC-SHA1");
            request.AddParameter("oauth_version", "1.0");
            request.AddParameter("oauth_signature", sig);
        }
 public IEnumerable<OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset? since)
 {
     return _youTrackApi.GetClosedIssues(context, since).ToArray();
 }
 public Repository(IIssueTrackerContext context)
 {
     this.EntityTable = context.Set <T>();
 }
 public IEnumerable<OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset? since)
 {
     return _bitBucketApi.GetClosedIssues(context, since, _accountName, _repoSlug, _oauth).ToArray();
 }
 public IEnumerable <OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset?since)
 {
     return(_youTrackApi.GetClosedIssues(context, since).ToArray());
 }
示例#13
0
 public IEnumerable <OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset?since)
 {
     return(_bitBucketApi.GetClosedIssues(context, since, _accountName, _repoSlug, _oauth).ToArray());
 }
示例#14
0
        public IEnumerable<OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset? since)
        {
            var youTrackContext = (YouTrackContext) context;

            var authenticationCookies = ConnectToYouTrack(context.Username, context.Password, context.Url);
            return IssuesClosedSinceDate(
                authenticationCookies,
                youTrackContext.Filter,
                context.Url,
                context.ProjectId,
                since);
        }
 public IssueTrackerData(IIssueTrackerContext context)
 {
     this.context = context;
 }
示例#16
0
 public Context(IIssueTrackerContext issueTrackerContext)
 {
     Repository = new RepositoryContext();
     IssueTracker = issueTrackerContext;
 }
        public IEnumerable<OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset? since)
        {
            string organisation;
            string repository;
            GetRepository(out organisation, out repository);

            var gitHubClient = _gitHubClientFactory();
            var forRepository = gitHubClient.Issue.GetForRepository(organisation, repository, new RepositoryIssueRequest
            {
                Filter = IssueFilter.All,
                Since = since,
                State = ItemState.Closed
            });

            var readOnlyList = forRepository.Result.Where(i => i.ClosedAt > since);

            var userCache = new Dictionary<string, User>();
            Func<User, string> getUserName = u =>
            {
                var login = u.Login;
                if (!userCache.ContainsKey(login))
                {
                    userCache.Add(login, string.IsNullOrEmpty(u.Name) ? gitHubClient.User.Get(login).Result : u);
                }

                var user = userCache[login];
                if (user != null)
                {
                    return user.Name;
                }

                return null;
            };
            return readOnlyList.Select(i => new OnlineIssue("#" + i.Number.ToString(CultureInfo.InvariantCulture), i.ClosedAt.Value)
            {
                HtmlUrl = i.HtmlUrl,
                Title = i.Title,
                IssueType = i.PullRequest == null ? IssueType.Issue : IssueType.PullRequest,
                Labels = i.Labels.Select(l => l.Name).ToArray(),
                Contributors = i.PullRequest == null ? new GitReleaseNotes.Contributor[0] : new[]
                {
                    new GitReleaseNotes.Contributor(getUserName(i.User), i.User.Login, i.User.HtmlUrl)
                }
            });
        }
示例#18
0
        public IEnumerable <OnlineIssue> GetClosedIssues(IIssueTrackerContext context, DateTimeOffset?since)
        {
            var jiraContext = (JiraContext)context;

            Atlassian.Jira.Jira jira = null;

            if (!string.IsNullOrWhiteSpace(jiraContext.Token))
            {
                Log.WriteLine("Using jira with authentication token");

                jira = new Atlassian.Jira.Jira(jiraContext.Url, jiraContext.Token);
            }
            else if (!string.IsNullOrWhiteSpace(jiraContext.Username) && !string.IsNullOrWhiteSpace(jiraContext.Password))
            {
                Log.WriteLine("Using jira with username and password");

                jira = new Atlassian.Jira.Jira(jiraContext.Url, jiraContext.Username, jiraContext.Password);
            }
            else
            {
                Log.WriteLine("Using jira without authentication");

                jira = new Atlassian.Jira.Jira(jiraContext.Url);
            }

            var jql = jiraContext.Jql;

            if (string.IsNullOrEmpty(jql))
            {
                jql = string.Format("project = {0}", jiraContext.ProjectId);

                try
                {
                    var issueTypes = jira.GetIssueTypes(jiraContext.ProjectId);
                    jql += string.Format(" AND issuetype in ({0})", string.Join(", ", issueTypes.Select(x => string.Format("\"{0}\"", x.Name))));
                }
                catch (Exception ex)
                {
                    Log.WriteLine("Failed to retrieve issue types, defaulting to all issue types");
                }

                try
                {
                    var issueStatuses = jira.GetIssueStatuses();
                    jql += string.Format(" AND status in ({0})", string.Join(", ", issueStatuses.Where(x => _knownIssueStatuses.Contains(x.Name.ToLower())).Select(x => string.Format("\"{0}\"", x.Name))));
                }
                catch (Exception ex)
                {
                    Log.WriteLine("Failed to retrieve issue statuses, defaulting to issue statuses issue 'Closed'");

                    jql += " AND status in (Closed)";
                }
            }

            if (since.HasValue)
            {
                var sinceFormatted = since.Value.ToString("yyyy-MM-d HH:mm");
                jql += string.Format(" AND updated > '{0}'", sinceFormatted).Replace("\"", "\\\"");
            }

            // Update back so every component is aware of the new jql
            jiraContext.Jql = jql;

            var issues = jira.GetIssuesFromJql(jql, 200);

            foreach (var issue in issues)
            {
                var summary = issue.Summary;
                var id      = issue.Key.Value;
                //var issueType = issue.Type.Name;

                var closedDate = issue.Created ?? DateTime.Today;

                try
                {
                    closedDate = issue.GetResolutionDate() ?? DateTime.Today;
                }
                catch (Exception)
                {
                    Log.WriteLine("Failed to retrieve the resolution date of '{0}', falling back to creation date", id);
                }

                yield return(new OnlineIssue(id, new DateTimeOffset(closedDate))
                {
                    Title = summary,
                    IssueType = IssueType.Issue,
                    HtmlUrl = new Uri(new Uri(jiraContext.Url), string.Format("browse/{0}", id))
                });
            }
        }