/// <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); } }
/// <summary> /// Gets all PRs for a given repository /// </summary> /// <param name="repoId"></param> /// <param name="filter"></param> /// <returns></returns> public static async Task <ObservableCollection <PullRequest> > GetAllPullRequestsForRepo(long repoId, PullRequestRequest filter) { try { var client = await UserUtility.GetAuthenticatedClient(); var prList = await client.PullRequest.GetAllForRepository(repoId, filter); return(new ObservableCollection <PullRequest>(prList)); } catch { return(null); } }
/// <summary> /// Gets all repositories owned by a given user /// </summary> /// <param name="login"></param> /// <returns></returns> public static async Task <ObservableCollection <Repository> > GetRepositoriesForUser(string login) { try { var client = await UserUtility.GetAuthenticatedClient(); var result = await client.Repository.GetAllForUser(login); return(new ObservableCollection <Repository>(result)); } catch { return(null); } }
/// <summary> /// Gets contents of a given repository, branch and path (Text) /// </summary> /// <param name="repo"></param> /// <param name="path"></param> /// <param name="branch"></param> /// <returns></returns> public static async Task <RepositoryContent> GetRepositoryContentTextByPath(Repository repo, string path, string branch) { try { GitHubClient client = await UserUtility.GetAuthenticatedClient(); var results = await client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch); return(results.First()); } catch { return(null); } }
/// <summary> /// Gets all issues for a given repository /// </summary> /// <param name="repoId"></param> /// <param name="filter"></param> /// <returns></returns> public static async Task <ObservableCollection <Issue> > GetAllIssuesForRepo(long repoId, RepositoryIssueRequest filter) { try { var client = await UserUtility.GetAuthenticatedClient(); var issues = await client.Issue.GetAllForRepository(repoId, filter); return(new ObservableCollection <Issue>(issues)); } catch { return(null); } }
/// <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); } }
/// <summary> /// Watches a repository /// </summary> /// <param name="repo"></param> /// <returns></returns> public static async Task <bool> WatchRepository(Repository repo) { try { GitHubClient client = await UserUtility.GetAuthenticatedClient(); return((await client.Activity.Watching.WatchRepo(repo.Id, new NewSubscription { Subscribed = true })).Subscribed); } catch { return(false); } }
/// <summary> /// Gets all commits for a specified pull request /// </summary> /// <param name="repoId"></param> /// <param name="number"></param> /// <returns></returns> public static async Task <ObservableCollection <PullRequestCommit> > GetAllCommitsForPullRequest(long repoId, int number) { try { var client = await UserUtility.GetAuthenticatedClient(); var commits = await client.PullRequest.Commits(repoId, number); return(new ObservableCollection <PullRequestCommit>(commits)); } catch { return(null); } }
/// <summary> /// Searches issues /// </summary> /// <param name="query"></param> /// <returns></returns> public static async Task <ObservableCollection <Issue> > SearchIssues(string query) { try { var client = await UserUtility.GetAuthenticatedClient(); var request = new SearchIssuesRequest(query); var result = await client.Search.SearchIssues(request); return(new ObservableCollection <Issue>(new List <Issue>(result.Items))); } catch { return(null); } }
/// <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); return(new ObservableCollection <GitHubCommit>(list)); } catch { return(null); } }
/// <summary> /// Gets all Notifications for the current user /// </summary> /// <param name="all"></param> /// <param name="participating"></param> /// <returns></returns> public static async Task <ObservableCollection <Notification> > GetAllNotificationsForCurrentUser(bool all, bool participating) { try { var client = await UserUtility.GetAuthenticatedClient(); NotificationsRequest req = new NotificationsRequest { All = all, Participating = participating }; ApiOptions options = new ApiOptions { PageSize = 100, PageCount = 1 }; return(new ObservableCollection <Notification>(await client.Activity.Notifications.GetAllForCurrent(req, options))); } catch { return(null); } }
/// <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 }); return(new ObservableCollection <Issue>(issues)); } catch { return(null); } }
/// <summary> /// Gets all contributors for a repository /// </summary> /// <param name="repoId"></param> /// <returns></returns> public static async Task <ObservableCollection <RepositoryContributor> > GetContributorsForRepository(long repoId) { try { GitHubClient client = await UserUtility.GetAuthenticatedClient(); ApiOptions options = new ApiOptions { PageCount = 1, PageSize = 100 }; var users = await client.Repository.GetAllContributors(repoId, options); return(new ObservableCollection <RepositoryContributor>(users)); } catch { return(null); } }
/// <summary> /// Gets all public events of a given user /// </summary> /// <param name="login"></param> /// <returns></returns> public static async Task <ObservableCollection <Activity> > GetUserPerformedActivity(string login) { try { var client = await UserUtility.GetAuthenticatedClient(); ApiOptions options = new ApiOptions { PageSize = 10, PageCount = 1 }; var result = await client.Activity.Events.GetAllUserPerformedPublic(login, options); return(new ObservableCollection <Activity>(result)); } catch { return(null); } }
/// <summary> /// Gets names of all branches of a given repository /// </summary> /// <param name="repo"></param> /// <returns></returns> public static async Task <ObservableCollection <string> > GetAllBranches(Repository repo) { try { var client = await UserUtility.GetAuthenticatedClient(); var branches = await client.Repository.Branch.GetAll(repo.Owner.Login, repo.Name); ObservableCollection <string> branchList = new ObservableCollection <string>(); foreach (Branch i in branches) { branchList.Add(i.Name); } return(branchList); } catch { return(null); } }
/// <summary> /// Gets a notification /// </summary> /// <param name="notificationId"></param> /// <returns></returns> public static async Task <Notification> GetNotificationById(string notificationId) { try { var client = await UserUtility.GetAuthenticatedClient(); if (int.TryParse(notificationId, out int id)) { return(await client.Activity.Notifications.Get(id)); } else { return(null); } } catch { return(null); } }
/// <summary> /// Gets all public events of current user /// </summary> /// <returns></returns> public static async Task <ObservableCollection <Activity> > GetUserActivity() { try { var client = await UserUtility.GetAuthenticatedClient(); var options = new ApiOptions { PageSize = 50, PageCount = 1 }; var result = await client.Activity.Events.GetAllUserReceivedPublic(GlobalHelper.UserLogin, options); return(new ObservableCollection <Activity>(result)); } catch { return(null); } }
/// <summary> /// Gets all comments for a given issue /// </summary> /// <param name="owner"></param> /// <param name="name"></param> /// <param name="number"></param> /// <returns></returns> public static async Task <ObservableCollection <IssueComment> > GetAllCommentsForIssue(string owner, string name, int number) { try { var client = await UserUtility.GetAuthenticatedClient(); var comments = await client.Issue.Comment.GetAllForIssue(owner, name, number); ObservableCollection <IssueComment> commentList = new ObservableCollection <IssueComment>(); foreach (IssueComment c in comments) { commentList.Add(c); } return(commentList); } catch { return(null); } }
/// <summary> /// Gets all issues for a given repository /// </summary> /// <param name="repoId"></param> /// <param name="filter"></param> /// <returns></returns> public static async Task <ObservableCollection <Issue> > GetAllIssuesForRepo(long repoId, RepositoryIssueRequest filter) { try { var client = await UserUtility.GetAuthenticatedClient(); var issues = await client.Issue.GetAllForRepository(repoId, filter); ObservableCollection <Issue> issueList = new ObservableCollection <Issue>(); foreach (Issue c in issues) { issueList.Add(c); } return(issueList); } catch { return(null); } }
public static async Task <ObservableCollection <Issue> > SearchIssues(string query) { try { var client = await UserUtility.GetAuthenticatedClient(); var request = new SearchIssuesRequest(query); var result = await client.Search.SearchIssues(request); ObservableCollection <Issue> issues = new ObservableCollection <Issue>(); foreach (Issue r in result.Items) { issues.Add(r); } return(issues); } catch { return(null); } }
public static async Task <ObservableCollection <Repository> > SearchRepos(string query) { try { var client = await UserUtility.GetAuthenticatedClient(); var request = new SearchRepositoriesRequest(query); var result = await client.Search.SearchRepo(request); ObservableCollection <Repository> repos = new ObservableCollection <Repository>(); foreach (Repository r in result.Items) { repos.Add(r); } return(repos); } catch { return(null); } }
/// <summary> /// Saves access token in device /// </summary> /// <param name="token"></param> /// <param name="clientId">Client Id is used as resource string for PasswordCredential</param> /// <returns></returns> private async Task <bool> SaveToken(string token, string clientId) { try { GlobalHelper.GithubClient = UserUtility.GetAuthenticatedClient(token); User user = await UserUtility.GetCurrentUserInfo(); var vault = new PasswordVault(); vault.Add(new PasswordCredential(clientId, user.Id.ToString(), token)); await AccountsService.AddUser(new Models.Account { Id = user.Id, AvatarUrl = user.AvatarUrl, IsLoggedIn = true, Login = user.Login, IsActive = true }); return(true); } catch { return(false); } }
/// <summary> /// Gets contents of a given repository, branch and path /// </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 { // Get the files list GitHubClient client = await UserUtility.GetAuthenticatedClient(); String url = $"{repo.HtmlUrl}/tree/{branch}/{path}"; IEnumerable <RepositoryContentWithCommitInfo> results = SettingsService.Get <bool>(SettingsKeys.LoadCommitsInfo) ? await TryLoadLinkedCommitDataAsync( client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch), url, client, repo.Id, branch, CancellationToken.None) : from item in await client.Repository.Content.GetAllContentsByRef(repo.Id, path, branch) select new RepositoryContentWithCommitInfo(item); return(new ObservableCollection <RepositoryContentWithCommitInfo>(results)); } catch { return(null); } }
/// <summary> /// Gets the preferred README's HTML for a repository /// </summary> /// <param name="repoId">Repsitory Id</param> /// <returns></returns> public static async Task <string> GetReadmeHTMLForRepository(long repoId) { GitHubClient client = await UserUtility.GetAuthenticatedClient(); return(await client.Repository.Content.GetReadmeHtml(repoId)); }
/// <summary> /// Removes a label from issue /// </summary> /// <param name="repoId"></param> /// <param name="number"></param> /// <param name="labelName"></param> /// <returns></returns> public static async Task RemoveLabelFromIssue(long repoId, int number, string labelName) { var client = await UserUtility.GetAuthenticatedClient(); await client.Issue.Labels.RemoveFromIssue(repoId, number, labelName); }
/// <summary> /// Marks all notifications as read /// </summary> /// <returns></returns> public static async Task MarkAllNotificationsAsRead() { var client = await UserUtility.GetAuthenticatedClient(); await client.Activity.Notifications.MarkAsRead(new MarkAsReadRequest()); }
/// <summary> /// Checks if the current user follows a given user /// </summary> /// <param name="login"></param> /// <returns></returns> public static async Task <bool> CheckFollow(string login) { var client = await UserUtility.GetAuthenticatedClient(); return(await client.User.Followers.IsFollowingForCurrent(login)); }
/// <summary> /// Unfollows a given user /// </summary> /// <param name="login"></param> /// <returns></returns> public static async Task UnFollowUser(string login) { var client = await UserUtility.GetAuthenticatedClient(); await client.User.Followers.Unfollow(login); }