示例#1
0
        /// <summary>
        /// Note: For private repositories, these links are temporary and expire quickly.
        /// </summary>
        public async Task <Uri> GetArchiveLinkAsync(GetArchiveLinkRequest request)
        {
            // GET /repos/:owner/:repo/:archive_format/:ref
            // https://api.github.com/repos/user/repo/zipball/dev

            var httpRequest = new HttpRequestMessage(
                method: HttpMethod.Get,
                requestUri: baseUri + request.ToPath()
                );

            httpRequest.Headers.Authorization = accessToken.ToHeader();

            using (var response = await httpClient.SendAsync(httpRequest).ConfigureAwait(false))
            {
                if (response.StatusCode != System.Net.HttpStatusCode.Redirect)
                {
                    var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    throw new Exception(httpRequest.RequestUri + " : " + responseText);
                }

                // Returns a 302 redirect
                var location = response.Headers.GetValues("Location").First();

                return(new Uri(location));
            }
        }
示例#2
0
        public async Task<IPackage> DownloadAsync(Revision revision)
        {
            var request = new GetArchiveLinkRequest(AccountName, RepositoryName, revision, format: ArchiveFormat.Zipball);

            var link = await client.GetArchiveLink(request).ConfigureAwait(false);

            return await ZipPackage.FetchAsync(link, stripFirstLevel: true).ConfigureAwait(false);
        }
示例#3
0
        public async Task <IPackage> DownloadAsync(Revision revision)
        {
            var request = new GetArchiveLinkRequest(
                accountName: AccountName,
                repositoryName: RepositoryName,
                revision: revision,
                format: GitArchiveFormat.Zipball
                );

            var link = await client.GetArchiveLinkAsync(request).ConfigureAwait(false);

            return(await ZipPackage.DownloadAsync(link, stripFirstLevel : true).ConfigureAwait(false));
        }
示例#4
0
        /// <summary>
        /// Note: For private repositories, these links are temporary and expire quickly.
        /// </summary>
        public async Task<Uri> GetArchiveLink(GetArchiveLinkRequest request)
        {
            // GET /repos/:owner/:repo/:archive_format/:ref
            // https://api.github.com/repos/user/repo/zipball/dev

            var requestUri = baseUri + request.ToPath();
            var httpRequest = new HttpRequestMessage(HttpMethod.Get, requestUri);

            httpRequest.Headers.Authorization = auth.ToHeader();
            httpRequest.Headers.UserAgent.Add(userAgent);

            using (var response = await httpClient.SendAsync(httpRequest).ConfigureAwait(false))
            {
                if (response.StatusCode != System.Net.HttpStatusCode.Redirect)
                {
                    var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    throw new Exception(requestUri + " : " + responseText);
                }

                // Returns a 302 redirect
                var location = response.Headers.GetValues("Location").First();

                return new Uri(location);
            }
        }