コード例 #1
0
        private static ApiConnection CreateApiConnection(string userName, string apiToken)
        {
            Credentials credentials;

            if (string.IsNullOrWhiteSpace(userName))
            {
                credentials = new Credentials(apiToken);
            }
            else
            {
                credentials = new Credentials(userName, apiToken);
            }

            var connection = new Connection(new ProductHeaderValue("Cake.GitHub"))
            {
                Credentials = credentials
            };

            var apiConnection = new Octokit.ApiConnection(connection);

            return(apiConnection);
        }
コード例 #2
0
 /// <summary>
 /// Uninstalls a GitHub App on a user, organization, or business account (requires GitHubApp auth).
 /// </summary>
 /// <remarks>https://docs.github.com/en/rest/apps/apps#delete-an-installation-for-the-authenticated-app</remarks>
 /// <param name="installationId">The Id of the GitHub App Installation</param>
 public Task DeleteInstallationForCurrent(long installationId)
 {
     return(ApiConnection.Delete(ApiUrls.Installation(installationId)));
 }
コード例 #3
0
        /// <summary>
        /// Gets the specified <see cref="ReleaseAsset"/> for the specified release of the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release-asset">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
        public Task <ReleaseAsset> GetAsset(long repositoryId, int assetId)
        {
            var endpoint = ApiUrls.Asset(repositoryId, assetId);

            return(ApiConnection.Get <ReleaseAsset>(endpoint));
        }
コード例 #4
0
        /// <summary>
        /// Gets the latest <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task <Release> GetLatest(long repositoryId)
        {
            var endpoint = ApiUrls.LatestRelease(repositoryId);

            return(ApiConnection.Get <Release>(endpoint));
        }
コード例 #5
0
 /// <summary>
 /// Gets a single event
 /// </summary>
 /// <remarks>
 /// http://developer.github.com/v3/issues/events/#get-a-single-event
 /// </remarks>
 /// <param name="repositoryId">The Id of the repository</param>
 /// <param name="eventId">The event id</param>
 public Task <IssueEvent> Get(long repositoryId, long eventId)
 {
     return(ApiConnection.Get <IssueEvent>(ApiUrls.IssuesEvent(repositoryId, eventId),
                                           null,
                                           AcceptHeaders.IssueEventsApiPreview));
 }
コード例 #6
0
        /// <summary>
        /// Gets a single <see cref="Team"/> by identifier.
        /// </summary>
        /// <remarks>
        /// https://developer.github.com/v3/orgs/teams/#get-team
        /// </remarks>
        /// <param name="id">The team identifier.</param>
        /// <returns>The <see cref="Team"/> with the given identifier.</returns>
        public Task <Team> Get(int id)
        {
            var endpoint = ApiUrls.Teams(id);

            return(ApiConnection.Get <Team>(endpoint));
        }
コード例 #7
0
        /// <summary>
        /// Gets all  labels for the issue.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#list-labels-on-an-issue">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The number of the issue</param>
        /// <param name="options">Options for changing the API response</param>
        public Task <IReadOnlyList <Label> > GetAllForIssue(long repositoryId, int number, ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            return(ApiConnection.GetAll <Label>(ApiUrls.IssueLabels(repositoryId, number), null, AcceptHeaders.LabelsApiPreview, options));
        }
コード例 #8
0
        /// <summary>
        /// Replaces all labels on the specified issues with the provided labels
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The number of the issue</param>
        /// <param name="labels">The names of the labels to set</param>
        public Task <IReadOnlyList <Label> > ReplaceAllForIssue(long repositoryId, int number, string[] labels)
        {
            Ensure.ArgumentNotNull(labels, nameof(labels));

            return(ApiConnection.Put <IReadOnlyList <Label> >(ApiUrls.IssueLabels(repositoryId, number), labels, AcceptHeaders.LabelsApiPreview));
        }
コード例 #9
0
 /// <summary>
 /// Retrives a single <see cref="Notification"/> by Id.
 /// </summary>
 /// <param name="id">The Id of the notification to retrieve.</param>
 /// <remarks>http://developer.github.com/v3/activity/notifications/#view-a-single-thread</remarks>
 /// <returns>A <see cref="Notification"/> for the given Id.</returns>
 public Task <Notification> Get(int id)
 {
     return(ApiConnection.Get <Notification>(ApiUrls.Notification(id)));
 }
コード例 #10
0
        /// <summary>
        /// Marks all notifications as read.
        /// </summary>
        /// <param name="markAsReadRequest">The <see cref="MarkAsReadRequest"/> parameter which specifies which notifications to mark.</param>
        /// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
        /// <returns></returns>
        public Task MarkAsRead(MarkAsReadRequest markAsReadRequest)
        {
            Ensure.ArgumentNotNull(markAsReadRequest, "markAsReadRequest");

            return(ApiConnection.Put <object>(ApiUrls.Notifications(), markAsReadRequest));
        }
コード例 #11
0
 /// <summary>
 /// Marks all notifications as read.
 /// </summary>
 /// <remarks>http://developer.github.com/v3/activity/notifications/#mark-as-read</remarks>
 /// <returns></returns>
 public Task MarkAsRead()
 {
     return(ApiConnection.Put(ApiUrls.Notifications()));
 }
コード例 #12
0
 public Task <Installation> GetInstallationForCurrent(long installationId)
 {
     return(ApiConnection.Get <Installation>(ApiUrls.Installation(installationId), null, AcceptHeaders.GitHubAppsPreview));
 }
コード例 #13
0
        public Task <IReadOnlyList <Installation> > GetAllInstallationsForCurrent(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            return(ApiConnection.GetAll <Installation>(ApiUrls.Installations(), null, AcceptHeaders.GitHubAppsPreview, options));
        }
コード例 #14
0
 public Task <GitHubApp> GetCurrent()
 {
     return(ApiConnection.Get <GitHubApp>(ApiUrls.App(), null, AcceptHeaders.GitHubAppsPreview));
 }
コード例 #15
0
        public Task <GitHubApp> Get(string slug)
        {
            Ensure.ArgumentNotNullOrEmptyString(slug, nameof(slug));

            return(ApiConnection.Get <GitHubApp>(ApiUrls.App(slug), null, AcceptHeaders.GitHubAppsPreview));
        }
コード例 #16
0
        /// <summary>
        /// Creates a label.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#create-a-label">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newLabel">The data for the label to be created</param>
        public Task <Label> Create(long repositoryId, NewLabel newLabel)
        {
            Ensure.ArgumentNotNull(newLabel, nameof(newLabel));

            return(ApiConnection.Post <Label>(ApiUrls.Labels(repositoryId), newLabel, AcceptHeaders.LabelsApiPreview));
        }
コード例 #17
0
        /// <summary>
        /// Removes a label from an issue
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The number of the issue</param>
        /// <param name="labelName">The name of the label to remove</param>
        public Task <IReadOnlyList <Label> > RemoveFromIssue(long repositoryId, int number, string labelName)
        {
            Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));

            return(ApiConnection.Delete <IReadOnlyList <Label> >(ApiUrls.IssueLabel(repositoryId, number, labelName), AcceptHeaders.LabelsApiPreview));
        }
コード例 #18
0
 /// <summary>
 /// Marks a single notification as read.
 /// </summary>
 /// <param name="id">The id of the notification.</param>
 /// <remarks>http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read</remarks>
 /// <returns></returns>
 public Task MarkAsRead(int id)
 {
     return(ApiConnection.Patch(ApiUrls.Notification(id)));
 }
コード例 #19
0
 /// <summary>
 /// Removes all labels from an issue
 /// </summary>
 /// <remarks>
 /// See the <a href="http://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue">API documentation</a> for more information.
 /// </remarks>
 /// <param name="repositoryId">The Id of the repository</param>
 /// <param name="number">The number of the issue</param>
 public Task RemoveAllFromIssue(long repositoryId, int number)
 {
     return(ApiConnection.Delete(ApiUrls.IssueLabels(repositoryId, number)));
 }
コード例 #20
0
 /// <summary>
 /// Retrives a <see cref="ThreadSubscription"/> for the provided thread id.
 /// </summary>
 /// <param name="id">The Id of the thread to retrieve subscription status.</param>
 /// <remarks>http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription</remarks>
 /// <returns>A <see cref="ThreadSubscription"/> for the chosen thread.</returns>
 public Task <ThreadSubscription> GetThreadSubscription(int id)
 {
     return(ApiConnection.Get <ThreadSubscription>(ApiUrls.NotificationSubscription(id)));
 }
コード例 #21
0
        /// <summary>
        /// Delte a team - must have owner permissions to this
        /// </summary>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns></returns>
        public Task Delete(int id)
        {
            var endpoint = ApiUrls.Teams(id);

            return(ApiConnection.Delete(endpoint));
        }
コード例 #22
0
        /// <summary>
        /// Sets the authenticated user's subscription settings for a given thread.
        /// </summary>
        /// <param name="id">The Id of the thread to update.</param>
        /// <param name="threadSubscription">The subscription parameters to set.</param>
        /// <remarks>http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription</remarks>
        /// <returns></returns>
        public Task <ThreadSubscription> SetThreadSubscription(int id, NewThreadSubscription threadSubscription)
        {
            Ensure.ArgumentNotNull(threadSubscription, "threadSubscription");

            return(ApiConnection.Put <ThreadSubscription>(ApiUrls.NotificationSubscription(id), threadSubscription));
        }
コード例 #23
0
        public Task <CombinedCommitStatus> GetCombined(long repositoryId, string reference)
        {
            Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));

            return(ApiConnection.Get <CombinedCommitStatus>(ApiUrls.CombinedCommitStatus(repositoryId, reference)));
        }
コード例 #24
0
 /// <summary>
 /// Deletes the authenticated user's subscription to a given thread.
 /// </summary>
 /// <param name="id">The Id of the thread to delete subscription from.</param>
 /// <remarks>http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription</remarks>
 /// <returns></returns>
 public Task DeleteThreadSubscription(int id)
 {
     return(ApiConnection.Delete(ApiUrls.NotificationSubscription(id)));
 }
コード例 #25
0
        /// <summary>
        /// Gets a single <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="id">The id of the release</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task <Release> Get(long repositoryId, int id)
        {
            var endpoint = ApiUrls.Releases(repositoryId, id);

            return(ApiConnection.Get <Release>(endpoint));
        }
コード例 #26
0
        /// <summary>
        /// Retrieves all of the <see cref="Notification"/>s for the current user.
        /// </summary>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
        /// <returns>A <see cref="IReadOnlyPagedCollection{Notification}"/> of <see cref="Notification"/>.</returns>
        public Task <IReadOnlyList <Notification> > GetAllForCurrent(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, "options");

            return(ApiConnection.GetAll <Notification>(ApiUrls.Notifications(), options));
        }
コード例 #27
0
        /// <summary>
        /// Deletes an existing <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#delete-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="id">The id of the release to delete</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task Delete(long repositoryId, int id)
        {
            var endpoint = ApiUrls.Releases(repositoryId, id);

            return(ApiConnection.Delete(endpoint));
        }
コード例 #28
0
        /// <summary>
        /// Gets a single Label by name.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#get-a-single-label">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="labelName">The name of the label</param>
        public Task <Label> Get(long repositoryId, string labelName)
        {
            Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));

            return(ApiConnection.Get <Label>(ApiUrls.Label(repositoryId, labelName), null, AcceptHeaders.LabelsApiPreview));
        }
コード例 #29
0
        /// <summary>
        /// Deletes a label.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#delete-a-label">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="labelName">The name of the label</param>
        public Task Delete(long repositoryId, string labelName)
        {
            Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));

            return(ApiConnection.Delete(ApiUrls.Label(repositoryId, labelName)));
        }
コード例 #30
0
        public Task <Installation> GetUserInstallationForCurrent(string user)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));

            return(ApiConnection.Get <Installation>(ApiUrls.UserInstallation(user), null, AcceptHeaders.GitHubAppsPreview));
        }