public void ParseBitbucket(string url) { var x = RevisionSource.Parse(url); Assert.Equal("bitbucket", x.Provider.Name); Assert.Equal("example", x.AccountName); Assert.Equal("repo", x.RepositoryName); }
public void ParseUrl(string url) { var x = RevisionSource.Parse(url); Assert.Equal("github", x.Provider.Name); Assert.Equal("carbon", x.AccountName); Assert.Equal("cropper", x.RepositoryName); Assert.Equal("branch", x.Revision.Value.Name); }
public void ParseTests() { var x = RevisionSource.Parse("npm/npm"); Assert.Equal("github", x.Provider.Name); Assert.Equal("npm", x.AccountName); Assert.Equal("npm", x.RepositoryName); Assert.Equal("npm/npm", x.ToString()); }
public void ParseTests2() { var x = RevisionSource.Parse("carbon/cropper#master"); Assert.Equal("github", x.Provider.Name); Assert.Equal("carbon", x.AccountName); Assert.Equal("cropper", x.RepositoryName); Assert.Equal("master", x.Revision.Value.Name); Assert.Equal("carbon/cropper#master", x.ToString()); }
public RepositoryClient(Uri url, OAuth2Token accessToken) { #region Preconditions if (url == null) { throw new ArgumentNullException(nameof(url)); } #endregion // https://github.com/{orgName}/{repoName}.git var info = RevisionSource.Parse(url); AccountName = info.AccountName; RepositoryName = info.RepositoryName; client = new GitHubClient(accessToken); }
public async Task <IRepositoryClient> GetAsync(IRepository repository) { Ensure.NotNull(repository, nameof(repository)); if (repository.EncryptedAccessToken == null) { throw new ArgumentException("Missing accessToken", nameof(repository)); } var origin = RevisionSource.Parse(repository.Origin); var accessTokenBytes = await dataDecryptor.DecryptAsync(repository.EncryptedAccessToken); var accessToken = new OAuth2Token(Encoding.UTF8.GetString(accessTokenBytes)); var client = new RepositoryClient( accountName: origin.AccountName, repositoryName: origin.RepositoryName, accessToken: accessToken ); return(client); }
// https://bitbucket.org/{accontName}/{repositoryName}.git public BitbucketRepository(Uri url, NetworkCredential credential) { #region Preconditions if (url == null) { throw new ArgumentNullException(nameof(url)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } #endregion var repo = RevisionSource.Parse(url); AccountName = repo.AccountName; RepositoryName = repo.RepositoryName; client = new BitbucketClient(credential); }
public async Task <WebLibrary> DeployAsync(IPackage package, RevisionSource source, int publisherId) { #region Preconditions if (package == null) { throw new ArgumentNullException(nameof(package)); } #endregion var metadata = GetMetadata(package); var version = metadata.Version; // var existing = await registry.GetAsync(registry.Lookup(metadata.Name), metadata.Version); // if (existing != null) throw new PublishingConflict(existing); var mainPath = metadata.Main; var bowerFile = package.Find("bower.json"); if (bowerFile != null) { try { var bowerFileStream = await bowerFile.OpenAsync().ConfigureAwait(false); var bower = PackageMetadata.Parse(bowerFileStream); if (bower.Main != null) { mainPath = bower.Main; } } catch { } } if (mainPath == null) { throw new Exception("A main property found in package.json or bower.json."); } var mainFile = package.Find(mainPath); if (mainFile == null) { throw new Exception($"The main file '{mainPath}' was not found"); } var mainText = await mainFile.ReadAllTextAsync().ConfigureAwait(false); if (mainText.Length == 0) { throw new Exception($"{mainPath} is empty"); } var mainBlobStream = new MemoryStream(Encoding.UTF8.GetBytes(mainText)); var mainName = mainPath.Split('/').Last(); if (!mainName.EndsWith(".js")) { throw new Exception($"Must end with js. was {mainName}"); } var mainBlob = new Blob( key: $"libs/{metadata.Name}/{version}/{mainName}", stream: mainBlobStream, properties: new BlobProperties { ContentType = "application/javascript" } ); var mainHash = Hash.ComputeSHA256(mainBlobStream); // Push to CDN await bucket.PutAsync(mainBlob).ConfigureAwait(false); if (metadata.Files != null) { // TODO: Copy over everything from files[] (excluding main) foreach (var fileName in metadata.Files) { var fn = fileName; if (fn.StartsWith("./")) { fn = fileName.Substring(2); } if (fn == mainPath) { continue; } var asset = package.Find(fn); var format = asset.Key.Split('.').Last(); var n = asset.Key.Split('/').Last(); var ms = new MemoryStream(); using (var data = await asset.OpenAsync().ConfigureAwait(false)) { data.CopyTo(ms); ms.Position = 0; } var blob = new Blob( key: $"libs/{metadata.Name}/{version}/{n}", stream: ms, properties: new BlobProperties { ContentType = GetMime(format) } ); await bucket.PutAsync(blob).ConfigureAwait(false); } } var release = new WebLibrary(metadata.Name, version) { MainName = mainName, MainSha256 = mainHash, Source = source.ToString() }; return(release); }