Exemplo n.º 1
0
 /// <summary>
 /// search repos
 /// http://developer.github.com/v3/search/#search-repositories
 /// </summary>
 /// <param name="search"></param>
 /// <returns>List of repos</returns>
 public Task <SearchRepositoryResult> SearchRepo(SearchRepositoriesRequest search)
 {
     Ensure.ArgumentNotNull(search, "search");
     return(ApiConnection.Get <SearchRepositoryResult>(ApiUrls.SearchRepositories(), search.Parameters));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a milestone for the specified repository. Any user with pull access to a repository can create an
        /// Milestone.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/milestones/#update-a-milestone</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The Milestone number</param>
        /// <param name="milestoneUpdate">An <see cref="MilestoneUpdate"/> instance describing the changes to make to the Milestone
        /// </param>
        /// <returns></returns>
        public Task <Milestone> Update(int repositoryId, int number, MilestoneUpdate milestoneUpdate)
        {
            Ensure.ArgumentNotNull(milestoneUpdate, "milestoneUpdate");

            return(ApiConnection.Patch <Milestone>(ApiUrls.Milestone(repositoryId, number), milestoneUpdate));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets all <see cref="Authorization"/>s for the authenticated user.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#list-your-authorizations">API documentation</a> for more information.
        /// </remarks>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make the request.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>A list of <see cref="Authorization"/>s for the authenticated user.</returns>
        public Task <IReadOnlyList <Authorization> > GetAll(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <Authorization>(ApiUrls.Authorizations(), options));
        }
Exemplo n.º 4
0
        public Task <IReadOnlyList <DeployKey> > GetAll(long repositoryId, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            return(ApiConnection.GetAll <DeployKey>(ApiUrls.RepositoryDeployKeys(repositoryId), options));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="request">Used to filter and sort the list of Milestones returned</param>
        /// <returns></returns>
        public Task <IReadOnlyList <Milestone> > GetAllForRepository(int repositoryId, MilestoneRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return(GetAllForRepository(repositoryId, request, ApiOptions.None));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a reaction for a specified Issue
        /// </summary>
        /// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-an-issue</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The issue id</param>
        /// <param name="reaction">The reaction to create</param>
        public Task <Reaction> Create(long repositoryId, int number, NewReaction reaction)
        {
            Ensure.ArgumentNotNull(reaction, nameof(reaction));

            return(ApiConnection.Post <Reaction>(ApiUrls.IssueReactions(repositoryId, number), reaction, AcceptHeaders.ReactionsPreview));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Merge a dictionary of values with an existing <see cref="Uri"/>
        /// </summary>
        /// <param name="uri">Original request Uri</param>
        /// <param name="parameters">Collection of key-value pairs</param>
        /// <returns>Updated request Uri</returns>
        public static Uri ApplyParameters(this Uri uri, IDictionary <string, string> parameters)
        {
            Ensure.ArgumentNotNull(uri, "uri");

            if (parameters == null || !parameters.Any())
            {
                return(uri);
            }

            // to prevent values being persisted across requests
            // use a temporary dictionary which combines new and existing parameters
            IDictionary <string, string> p = new Dictionary <string, string>(parameters);

            var hasQueryString = uri.OriginalString.IndexOf("?", StringComparison.Ordinal);

            string uriWithoutQuery = hasQueryString == -1
                    ? uri.ToString()
                    : uri.OriginalString.Substring(0, hasQueryString);

            string queryString;

            if (uri.IsAbsoluteUri)
            {
                queryString = uri.Query;
            }
            else
            {
                queryString = hasQueryString == -1
                    ? ""
                    : uri.OriginalString.Substring(hasQueryString);
            }

            var values = queryString.Replace("?", "")
                         .Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);

            var existingParameters = values.ToDictionary(
                key => key.Substring(0, key.IndexOf('=')),
                value => value.Substring(value.IndexOf('=') + 1));

            foreach (var existing in existingParameters)
            {
                if (!p.ContainsKey(existing.Key))
                {
                    p.Add(existing);
                }
            }

            Func <string, string, string> mapValueFunc = (key, value) => key == "q" ? value : Uri.EscapeDataString(value);

            string query = string.Join("&", p.Select(kvp => kvp.Key + "=" + mapValueFunc(kvp.Key, kvp.Value)));

            if (uri.IsAbsoluteUri)
            {
                var uriBuilder = new UriBuilder(uri)
                {
                    Query = query
                };
                return(uriBuilder.Uri);
            }

            return(new Uri(uriWithoutQuery + "?" + query, UriKind.Relative));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets all repositories owned by the current user.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#list-your-repositories">API documentation</a> for more information.
        /// </remarks>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
        public Task <IReadOnlyList <Repository> > GetAllForCurrent(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <Repository>(ApiUrls.Repositories(), options));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets all repositories owned by the current user.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#list-your-repositories">API documentation</a> for more information.
        /// The default page size on GitHub.com is 30.
        /// </remarks>
        /// <param name="request">Search parameters to filter results on</param>
        /// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
        public Task <IReadOnlyList <Repository> > GetAllForCurrent(RepositoryRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return(GetAllForCurrent(request, ApiOptions.None));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets all repositories owned by the current user.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#list-your-repositories">API documentation</a> for more information.
        /// </remarks>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
        public Task <IReadOnlyList <Repository> > GetAllForCurrent(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            return(ApiConnection.GetAll <Repository>(ApiUrls.Repositories(), null, AcceptHeaders.LicensesApiPreview, options));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the specified repository with the values given in <paramref name="update"/>
        /// </summary>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="update">New values to update the repository with</param>
        /// <returns>The updated <see cref="T:Octokit.Repository"/></returns>
        public Task <Repository> Edit(int repositoryId, RepositoryUpdate update)
        {
            Ensure.ArgumentNotNull(update, "update");

            return(ApiConnection.Patch <Repository>(ApiUrls.Repository(repositoryId), update));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Updates the specified repository with the values given in <paramref name="update"/>
        /// </summary>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="update">New values to update the repository with</param>
        /// <returns>The updated <see cref="T:Octokit.Repository"/></returns>
        public Task <Repository> Edit(long repositoryId, RepositoryUpdate update)
        {
            Ensure.ArgumentNotNull(update, nameof(update));

            return(ApiConnection.Patch <Repository>(ApiUrls.Repository(repositoryId), update, AcceptHeaders.Concat(AcceptHeaders.SquashCommitPreview, AcceptHeaders.LicensesApiPreview)));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Transfers the ownership of the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/repos/#transfer-a-repository">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The id of the repository</param>
        /// <param name="repositoryTransfer">Repository transfer information</param>
        /// <returns>A <see cref="Repository"/></returns>
        public Task <Repository> Transfer(long repositoryId, RepositoryTransfer repositoryTransfer)
        {
            Ensure.ArgumentNotNull(repositoryTransfer, nameof(repositoryTransfer));

            return(ApiConnection.Post <Repository>(ApiUrls.RepositoryTransfer(repositoryId), repositoryTransfer, AcceptHeaders.RepositoryTransferPreview));
        }
Exemplo n.º 14
0
 /// <summary>
 /// search code
 /// http://developer.github.com/v3/search/#search-code
 /// </summary>
 /// <param name="search"></param>
 /// <returns>List of files</returns>
 public Task <SearchCodeResult> SearchCode(SearchCodeRequest search)
 {
     Ensure.ArgumentNotNull(search, "search");
     return(ApiConnection.Get <SearchCodeResult>(ApiUrls.SearchCode(), search.Parameters));
 }
Exemplo n.º 15
0
        /// <summary>
        /// Updates a specified Issue Comment.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/comments/#edit-a-comment</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="id">The comment id</param>
        /// <param name="commentUpdate">The modified comment</param>
        public Task <IssueComment> Update(int repositoryId, int id, string commentUpdate)
        {
            Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");

            return(ApiConnection.Patch <IssueComment>(ApiUrls.IssueComment(repositoryId, id), new BodyWrapper(commentUpdate)));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a new repository for the current user.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#create">API documentation</a> for more information.
        /// </remarks>
        /// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>A <see cref="Repository"/> instance for the created repository.</returns>
        public Task <Repository> Create(NewRepository newRepository)
        {
            Ensure.ArgumentNotNull(newRepository, "newRepository");

            return(Create(ApiUrls.Repositories(), null, newRepository));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets Issue Comments for a repository.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="options">Options for changing the API response</param>
        public Task <IReadOnlyList <IssueComment> > GetAllForRepository(int repositoryId, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <IssueComment>(ApiUrls.IssueComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets all the branches for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#list-branches">API documentation</a> for more details
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>All <see cref="T:Octokit.Branch"/>es of the repository</returns>
        public Task <IReadOnlyList <Branch> > GetAllBranches(int repositoryId, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <Branch>(ApiUrls.RepoBranches(repositoryId), null, AcceptHeaders.ProtectedBranchesApiPreview, options));
        }
Exemplo n.º 19
0
 public PunchCard(IEnumerable <IList <int> > punchCardData)
 {
     Ensure.ArgumentNotNull(punchCardData, "punchCardData");
     PunchPoints = new ReadOnlyCollection <PunchCardPoint>(
         punchCardData.Select(point => new PunchCardPoint(point)).ToList());
 }
Exemplo n.º 20
0
        /// <summary>
        /// Gets all contributors for the specified repository. Does not include anonymous contributors.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#list-contributors">API documentation</a> for more details
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="options">Options for changing the API response</param>
        /// <returns>All contributors of the repository.</returns>
        public Task <IReadOnlyList <RepositoryContributor> > GetAllContributors(int repositoryId, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(GetAllContributors(repositoryId, false, options));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Initializes a new GitHub miscellaneous API client.
        /// </summary>
        /// <param name="connection">An API connection</param>
        public MiscellaneousClient(IConnection connection)
        {
            Ensure.ArgumentNotNull(connection, "connection");

            _connection = connection;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets all tags for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/#list-tags">API documentation</a> for more details
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="options">Options for changing the API response</param>
        /// <returns>All of the repositories tags.</returns>
        public Task <IReadOnlyList <RepositoryTag> > GetAllTags(int repositoryId, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <RepositoryTag>(ApiUrls.RepositoryTags(repositoryId), options));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="options">Options for changing the API response</param>
        /// <returns></returns>
        public Task <IReadOnlyList <Milestone> > GetAllForRepository(int repositoryId, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(GetAllForRepository(repositoryId, new MilestoneRequest(), options));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Updates Check Suites preferences on a repository, such as disabling automatic creation when code is pushed
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/checks/suites/#set-preferences-for-check-suites-on-a-repository">Check Suites API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="preferences">The check suite preferences</param>
        public Task <CheckSuitePreferencesResponse> UpdatePreferences(long repositoryId, CheckSuitePreferences preferences)
        {
            Ensure.ArgumentNotNull(preferences, nameof(preferences));

            return(ApiConnection.Patch <CheckSuitePreferencesResponse>(ApiUrls.CheckSuitePreferences(repositoryId), preferences, AcceptHeaders.ChecksApiPreview));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Creates a milestone for the specified repository. Any user with pull access to a repository can create an
        /// Milestone.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param>
        /// <returns></returns>
        public Task <Milestone> Create(int repositoryId, NewMilestone newMilestone)
        {
            Ensure.ArgumentNotNull(newMilestone, "newMilestone");

            return(ApiConnection.Post <Milestone>(ApiUrls.Milestones(repositoryId), newMilestone));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates a new Check Suite
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/checks/suites/#create-a-check-suite">Check Suites API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newCheckSuite">Details of the Check Suite to create</param>
        public Task <CheckSuite> Create(long repositoryId, NewCheckSuite newCheckSuite)
        {
            Ensure.ArgumentNotNull(newCheckSuite, nameof(newCheckSuite));

            return(ApiConnection.Post <CheckSuite>(ApiUrls.CheckSuites(repositoryId), newCheckSuite, AcceptHeaders.ChecksApiPreview));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Constructs an instance of RateLimitExceededException
        /// </summary>
        /// <param name="response">The HTTP payload from the server</param>
        /// <param name="innerException">The inner exception</param>
        public RateLimitExceededException(IResponse response, Exception innerException) : base(response, innerException)
        {
            Ensure.ArgumentNotNull(response, "response");

            _rateLimit = response.ApiInfo.RateLimit;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a new Issue Comment for a specified Issue.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/comments/#create-a-comment</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The number of the issue</param>
        /// <param name="newComment">The new comment to add to the issue</param>
        public Task <IssueComment> Create(int repositoryId, int number, string newComment)
        {
            Ensure.ArgumentNotNull(newComment, "newComment");

            return(ApiConnection.Post <IssueComment>(ApiUrls.IssueComments(repositoryId, number), new BodyWrapper(newComment)));
        }
Exemplo n.º 29
0
        public Task <IReadOnlyList <Gist> > GetAllStarred(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            return(ApiConnection.GetAll <Gist>(ApiUrls.StarredGists(), options));
        }
        /// <summary>
        /// Gets all email addresses for the authenticated user.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
        /// </remarks>
        /// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
        public Task <IReadOnlyList <EmailAddress> > GetAll(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <EmailAddress>(ApiUrls.Emails(), options));
        }