public async Task <bool> UpdateVersions() { var repository = new MongoRepository <Revision>(); string result = null; var revisionsFromGitHub = (await GetTagsFromGitHub()).Select(x => new Revision { Id = Guid.NewGuid().ToString(), Commit = x.Commit.Sha, Tag = x.Name }).ToList(); revisionsFromGitHub.Add(await GetDefaultRevision()); //Existing Revisions, we ignore version number tags to prevent building a version from an alternate commit. //existing revisions => update var updatesRevisions = repository .AsEnumerable() .Where(revision => !IsVersionNumber(revision)) .Join(revisionsFromGitHub, rev => rev.Tag, revBitbucket => revBitbucket.Tag, (rev, revBitbucket) => new Revision { Id = rev.Id, Tag = rev.Tag, Commit = revBitbucket.Commit, Hidden = rev.Hidden, CustomerVisible = rev.CustomerVisible, Inactive = rev.Inactive, }) .ToArray(); if (updatesRevisions.Any()) { repository.Update(updatesRevisions); } var tagsFromRepository = repository.Select(x => x.Tag).ToList(); //new revisions in bitbucket => add to repository var newRevisions = revisionsFromGitHub.Where(x => !tagsFromRepository.Contains(x.Tag)).ToList(); if (newRevisions.Any()) { repository.Add(newRevisions); } //var hasMoreThan100Tags = links != null ? true : false; return(false); }
public Task <bool> UpdateVersions() { var repository = new MongoRepository <Revision>(); var req = WebRequest.Create("https://bitbucket.org/api/1.0/repositories/apcurium/mk-taxi/tags") as HttpWebRequest; var authInfo = "buildapcurium:apcurium5200!"; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); req.Headers["Authorization"] = "Basic " + authInfo; string result = null; using (var resp = req.GetResponse() as HttpWebResponse) { var reader = new StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); } var revisionsFromBitBucket = JsonConvert.DeserializeObject <Dictionary <string, BitBucketRepoResponse> >(result) .Select(x => new Revision { Id = Guid.NewGuid().ToString(), Commit = x.Value.node, Tag = x.Key }).ToList(); revisionsFromBitBucket.Add(GetDefaultRevision()); //Existing Revisions, we ignore version number tags to prevent building a version from an alternate commit. //existing revisions => update var updatesRevisions = repository .AsEnumerable() .Where(revision => !IsVersionNumber(revision)) .Join(revisionsFromBitBucket, rev => rev.Tag, revBitbucket => revBitbucket.Tag, (rev, revBitbucket) => new Revision { Id = rev.Id, Tag = rev.Tag, Commit = revBitbucket.Commit, Hidden = rev.Hidden, CustomerVisible = rev.CustomerVisible, Inactive = rev.Inactive, }) .ToArray(); if (updatesRevisions.Any()) { repository.Update(updatesRevisions); } var tagsFromRepository = repository.Select(x => x.Tag).ToList(); //new revisions in bitbucket => add to repository var newRevisions = revisionsFromBitBucket.Where(x => !tagsFromRepository.Contains(x.Tag)).ToList(); if (newRevisions.Any()) { repository.Add(newRevisions); } return(Task.Run(() => { return false; })); }