Пример #1
0
        /// <summary>
        /// Gets all commits for a given file path
        /// </summary>
        /// <param name="repoId">Repository Id</param>
        /// <param name="path">file path</param>
        /// <returns></returns>
        public static async Task <ObservableCollection <GitHubCommit> > GetAllCommitsForFile(long repoId, string path)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                CommitRequest request = new CommitRequest {
                    Path = path
                };

                var list = await client.Repository.Commit.GetAll(repoId, request);

                ObservableCollection <GitHubCommit> commitList = new ObservableCollection <GitHubCommit>();

                foreach (GitHubCommit c in list)
                {
                    commitList.Add(c);
                }
                return(commitList);
            }
            catch
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Two calls are made to this method to emulate Incremental Loading. First call (second parameter = true) returns first 7 repositories,
        /// Second call (second parameter = false) returns the rest
        ///</summary>
        /// <param name="range">Today, weekly or monthly</param>
        /// <param name="firstCall">Indicates if this is the first call in incremental calls or not</param>
        /// <returns>Trending Repositories in a Time range</returns>
        public static async Task <ObservableCollection <Repository> > GetTrendingRepos(TimeRange range, bool firstCall)
        {
            try
            {
                ObservableCollection <Repository> repos = new ObservableCollection <Repository>();
                var trendingReposNames = await HtmlParseService.ExtractTrendingRepos(range);

                var client = await UserUtility.GetAuthenticatedClient();

                if (firstCall)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        repos.Add(await client.Repository.Get(trendingReposNames[i].Item1, trendingReposNames[i].Item2));
                    }
                }
                else
                {
                    for (int i = 7; i < trendingReposNames.Count; i++)
                    {
                        repos.Add(await client.Repository.Get(trendingReposNames[i].Item1, trendingReposNames[i].Item2));
                    }
                }

                return(repos);
            }
            catch
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets all issues started by the current user for a given repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <Issue> > GetAllIssuesForRepoByUser(long repoId)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                var issues = await client.Issue.GetAllForRepository(repoId, new RepositoryIssueRequest
                {
                    State   = ItemStateFilter.All,
                    Creator = GlobalHelper.UserLogin
                });

                ObservableCollection <Issue> issueList = new ObservableCollection <Issue>();
                foreach (Issue c in issues)
                {
                    issueList.Add(c);
                }

                return(issueList);
            }
            catch
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets contents of a given repository, branch and path (HTML)
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="path"></param>
        /// <param name="branch"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <RepositoryContentWithCommitInfo> > GetRepositoryContentByPath(Repository repo, string path, string branch)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                String url = $"{repo.HtmlUrl}/tree/{branch}/{path}";
                IEnumerable <RepositoryContentWithCommitInfo> results;

                if (SettingsService.Get <bool>(SettingsKeys.LoadCommitsInfo))
                {
                    results = await TryLoadLinkedCommitDataAsync(
                        client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch), url,
                        client, repo.Id, branch, CancellationToken.None);

                    return(new ObservableCollection <RepositoryContentWithCommitInfo>(results));
                }
                else
                {
                    results = from item in await client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch)
                              select new RepositoryContentWithCommitInfo(item);

                    return(new ObservableCollection <RepositoryContentWithCommitInfo>(results.OrderByDescending(entry => entry.Content.Type)));
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #5
0
        /// <summary>
        /// Marks a notification as read
        /// </summary>
        /// <param name="notificationId"></param>
        /// <returns></returns>
        public static async Task MarkNotificationAsRead(string notificationId)
        {
            var client = await UserUtility.GetAuthenticatedClient();

            if (int.TryParse(notificationId, out int id))
            {
                await client.Activity.Notifications.MarkAsRead(id);
            }
        }
Пример #6
0
        /// <summary>
        /// Returns trending repos. First call (second parameter = true) returns first 7 repositories,
        /// Second call (second parameter = false) returns the rest
        ///</summary>
        /// <param name="range">Today, weekly or monthly</param>
        /// <param name="firstCall">Indicates if this is the first call in incremental calls or not</param>
        /// <returns>Trending Repositories in a Time range</returns>
        public static async Task <ObservableCollection <Repository> > GetTrendingRepos(TimeRange range, bool firstCall)
        {
            try
            {
                ObservableCollection <Repository> repos     = new ObservableCollection <Repository>();
                List <Tuple <string, string> >    repoNames = new List <Tuple <string, string> >();

                if (firstCall)
                {
                    repoNames = await HtmlParseService.ExtractTrendingRepos(range);
                }
                else
                {
                    switch (range)
                    {
                    case TimeRange.TODAY:

                        repoNames = GlobalHelper.TrendingTodayRepoNames;
                        break;

                    case TimeRange.WEEKLY:

                        repoNames = GlobalHelper.TrendingWeekRepoNames;
                        break;

                    case TimeRange.MONTHLY:

                        repoNames = GlobalHelper.TrendingMonthRepoNames;
                        break;
                    }
                }

                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                if (firstCall)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        repos.Add(await client.Repository.Get(repoNames[i].Item1, repoNames[i].Item2));
                    }
                }
                else
                {
                    for (int i = 7; i < repoNames.Count; i++)
                    {
                        repos.Add(await client.Repository.Get(repoNames[i].Item1, repoNames[i].Item2));
                    }
                }

                return(repos);
            }
            catch
            {
                return(null);
            }
        }
Пример #7
0
        /// <summary>
        /// Gets a ThreadSubscription
        /// </summary>
        /// <param name="notificationId"></param>
        /// <returns></returns>
        public static async Task <ThreadSubscription> GetSubscribtionThread(string notificationId)
        {
            var client = await UserUtility.GetAuthenticatedClient();

            if (int.TryParse(notificationId, out int id))
            {
                return(await client.Activity.Notifications.GetThreadSubscription(id));
            }
            return(null);
        }
Пример #8
0
        /// <summary>
        ///  Gets all Notifications for a repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <Notification> > GetAllNotificationsForRepository(long repoId)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(new ObservableCollection <Notification>(await client.Activity.Notifications.GetAllForRepository(repoId)));
            }
            catch
            {
                return(null);
            }
        }
Пример #9
0
        /// <summary>
        /// Follows a given user
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public static async Task <bool> FollowUser(string login)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.User.Followers.Follow(login));
            }
            catch
            {
                return(false);
            }
        }
Пример #10
0
        /// <summary>
        /// Checks if a repository is watched by the authorized user
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        public static async Task <bool> CheckWatched(Repository repo)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Activity.Watching.CheckWatched(repo.Id));
            }
            catch
            {
                return(false);
            }
        }
Пример #11
0
        /// <summary>
        /// Forks a repository
        /// </summary>
        /// <param name="repo"></param>
        /// <returns>Forked repository</returns>
        public static async Task <Repository> ForkRepository(Repository repo)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                return(await client.Repository.Forks.Create(repo.Id, new NewRepositoryFork()));
            }
            catch
            {
                return(null);
            }
        }
Пример #12
0
        /// <summary>
        /// Unwatches a repository
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        public static async Task <bool> UnwatchRepository(Repository repo)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                return(await client.Activity.Watching.UnwatchRepo(repo.Id));
            }
            catch
            {
                return(false);
            }
        }
Пример #13
0
        /// <summary>
        /// Gets the preferred README for a repository
        /// </summary>
        /// <param name="repoId">Repsitory Id</param>
        /// <returns></returns>
        public static async Task <Readme> GetReadmeForRepository(long repoId)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                return(await client.Repository.Content.GetReadme(repoId));
            }
            catch
            {
                return(null);
            }
        }
Пример #14
0
        /// <summary>
        /// Gets a specified Repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <returns></returns>
        public static async Task <Repository> GetRepository(long repoId)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Repository.Get(repoId));
            }
            catch
            {
                return(null);
            }
        }
Пример #15
0
        /// <summary>
        /// Gets a Pull Request by number
        /// </summary>
        /// <param name="repoId"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        public static async Task <PullRequest> GetPullRequest(long repoId, int number)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.PullRequest.Get(repoId, number));
            }
            catch
            {
                return(null);
            }
        }
Пример #16
0
        /// <summary>
        /// Gets the Repository from repository name and owner name
        /// </summary>
        /// <param name="repoName"></param>
        /// <param name="ownerName"></param>
        /// <returns></returns>
        public static async Task <Repository> GetRepository(string repoName, string ownerName)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Repository.Get(repoName, ownerName));
            }
            catch
            {
                return(null);
            }
        }
Пример #17
0
        public static async Task <Organization> GetOrganizationInfo(string login)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                return(await client.Organization.Get(login));
            }
            catch
            {
                return(null);
            }
        }
Пример #18
0
        /// <summary>
        /// Checks if a repository is starred by the authorized user
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        public static async Task <bool> CheckStarred(Repository repo)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Activity.Starring.CheckStarred(repo.Owner.Login, repo.Name));
            }
            catch
            {
                return(false);
            }
        }
Пример #19
0
        /// <summary>
        /// Creates a new Issue for a repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <param name="newIssue"></param>
        /// <returns></returns>
        public static async Task <Issue> CreateIssue(long repoId, NewIssue newIssue)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Issue.Create(repoId, newIssue));
            }
            catch
            {
                return(null);
            }
        }
Пример #20
0
        /// <summary>
        /// Creates a new comment on a specified issue
        /// </summary>
        /// <param name="repoId"></param>
        /// <param name="number"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static async Task <IssueComment> CommentOnIssue(long repoId, int number, string comment)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Issue.Comment.Create(repoId, number, comment));
            }
            catch
            {
                return(null);
            }
        }
Пример #21
0
        /// <summary>
        /// Creates a new Label
        /// </summary>
        /// <param name="repoId"></param>
        /// <param name="newLabel"></param>
        /// <returns></returns>
        public static async Task <Label> CreateLabel(long repoId, NewLabel newLabel)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Issue.Labels.Create(repoId, newLabel));
            }
            catch
            {
                return(null);
            }
        }
Пример #22
0
        /// <summary>
        /// Updates an issue
        /// </summary>
        /// <param name="repoId"></param>
        /// <param name="number"></param>
        /// <param name="issueUpdate"></param>
        /// <returns></returns>
        public static async Task <Issue> EditIssue(long repoId, int number, IssueUpdate issueUpdate)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Issue.Update(repoId, number, issueUpdate));
            }
            catch
            {
                return(null);
            }
        }
Пример #23
0
        /// <summary>
        /// Creates a gist
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public static async Task <Gist> CreateGist(NewGist newGist)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                return(await client.Gist.Create(newGist));
            }
            catch
            {
                return(null);
            }
        }
Пример #24
0
        /// <summary>
        /// Sets the user's subscription settings for a given thread
        /// </summary>
        /// <param name="notificationId"></param>
        /// <param name="subscribed"></param>
        /// <param name="ignored"></param>
        /// <returns></returns>
        public static async Task SetThreadSubscription(string notificationId, bool subscribed, bool ignored)
        {
            var client = await UserUtility.GetAuthenticatedClient();

            if (int.TryParse(notificationId, out int id))
            {
                await client.Activity.Notifications.SetThreadSubscription(id,
                                                                          new NewThreadSubscription
                {
                    Subscribed = subscribed,
                    Ignored    = ignored
                });
            }
        }
Пример #25
0
        /// <summary>
        /// Gets all releases for a repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <Release> > GetReleasesForRepository(long repoId)
        {
            try
            {
                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                var releases = await client.Repository.Release.GetAll(repoId);

                return(new ObservableCollection <Release>(releases));
            }
            catch
            {
                return(null);
            }
        }
Пример #26
0
        /// <summary>
        /// Gets default branch for a given repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <returns></returns>
        public static async Task <string> GetDefaultBranch(long repoId)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                var repo = await client.Repository.Get(repoId);

                return(repo.DefaultBranch);
            }
            catch
            {
                return(null);
            }
        }
Пример #27
0
        /// <summary>
        /// Gets info of a given user
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public static async Task <User> GetUserInfo(string login)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                var user = await client.User.Get(login);

                return(user);
            }
            catch
            {
                return(null);
            }
        }
Пример #28
0
        /// <summary>
        /// Gets all comments for a given issue
        /// </summary>
        /// <param name="repoId"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <IssueComment> > GetAllCommentsForIssue(long repoId, int number)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                var comments = await client.Issue.Comment.GetAllForIssue(repoId, number);

                return(new ObservableCollection <IssueComment>(comments));
            }
            catch
            {
                return(null);
            }
        }
Пример #29
0
        /// <summary>
        /// Gets all labels in a repository
        /// </summary>
        /// <param name="repoId"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <Label> > GetAllLabelsForRepository(long repoId)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                var labels = await client.Issue.Labels.GetAllForRepository(repoId);

                return(new ObservableCollection <Label>(labels));
            }
            catch
            {
                return(null);
            }
        }
Пример #30
0
        /// <summary>
        /// Gets all gists for a user
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public static async Task <ObservableCollection <Gist> > GetGistsForUser(string login)
        {
            try
            {
                var client = await UserUtility.GetAuthenticatedClient();

                var gists = await client.Gist.GetAllForUser(login);

                return(new ObservableCollection <Gist>(new List <Gist>(gists)));
            }
            catch
            {
                return(null);
            }
        }