public async Task <bool> UpdateFile(Repository repository, RepositoryContent file, string content) { string url = file.DownloadUrl.AbsolutePath; string[] split = url.Split('/'); /* * TODO Splitting like this will not always yield positive results. * e.g. it'll be longer if the file is in a subfolder */ string owner = split[1]; string name = split[2]; string branch = split[3]; string path = split[4]; // Both seem to work now, since the branch has been specified var request = new UpdateFileRequest("test upload from octokit api", content, file.Sha, branch); try { await client.Repository.Content.UpdateFile(owner, name, path, request); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
private async Task <string> GetTargetPath(RepositoryContent sourceContent, PathGroupSpec pathSpec, RepositoryReference targetRepo) { var targetPath = pathSpec.DestinationPath; RepositoryContentEntry targetEntry; try { targetEntry = await GetRepositoryContentEntry(targetRepo, targetPath) .ConfigureAwait(continueOnCapturedContext: false); } catch (NotFoundException) { targetEntry = null; } switch (targetEntry) { case null when pathSpec.SourcePaths.Count > 1: case RepositoryContentEntry _ when !(targetEntry.Leaf is null) && targetEntry.Leaf.Type.TryParse(out var targetType) && targetType == ContentType.Dir: case RepositoryContentEntry _ when targetEntry.Leaf is null: return(pathSpec.DestinationPath.TrimEnd('/').TrimEnd() + "/" + sourceContent.Name); case null: return(targetPath); case RepositoryContentEntry _ when !(targetEntry.Leaf is null): return(targetEntry.Leaf.Path); } return(null); }
public override bool Evaluate(string sourcePath, RepositoryReference sourceRepo, RepositoryContent sourceContent, string targetPath, RepositoryReference targetRepo, RepositoryContent targetContent) { return(!(targetContent is null)); }
public async Task RepositoryContentObjectShouldAllowDownloadGitignoreFile() { //Arrange var repositoryOwner = "github"; var gitHubClient = new GitHubClient(new ProductHeaderValue("dotnet-ignore")); var repositoryName = "gitignore"; var httpClient = new HttpClient(); //Act IReadOnlyList <RepositoryContent> repositoryContents = await gitHubClient.Repository.Content.GetAllContents(repositoryOwner, repositoryName); RepositoryContent firstFile = repositoryContents .First(content => content.Type.Value == ContentType.File); HttpResponseMessage fileDownloadResponse = await httpClient.GetAsync(firstFile.DownloadUrl); string gitignoreFileContent = await fileDownloadResponse .Content .ReadAsStringAsync(); //Assert gitignoreFileContent .Should() .NotBeNullOrEmpty(); }
/// <summary> /// Gives the complete repository status /// </summary> /// <param name="org">Unique identifier of the organisation responsible for the app.</param> /// <param name="repository">The name of repository</param> /// <returns>The repository status</returns> public RepoStatus RepositoryStatus(string org, string repository) { RepoStatus repoStatus = new RepoStatus(); repoStatus.ContentStatus = new List <RepositoryContent>(); string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)); using (var repo = new LibGit2Sharp.Repository(localServiceRepoFolder)) { RepositoryStatus status = repo.RetrieveStatus(new LibGit2Sharp.StatusOptions()); foreach (StatusEntry item in status) { RepositoryContent content = new RepositoryContent(); content.FilePath = item.FilePath; content.FileStatus = (Altinn.Studio.Designer.Enums.FileStatus)(int) item.State; if (content.FileStatus == Enums.FileStatus.Conflicted) { repoStatus.RepositoryStatus = Enums.RepositoryStatus.MergeConflict; repoStatus.HasMergeConflict = true; } repoStatus.ContentStatus.Add(content); } LibGit2Sharp.Branch branch = repo.Branches.FirstOrDefault(b => b.IsTracking == true); if (branch != null) { repoStatus.AheadBy = branch.TrackingDetails.AheadBy; repoStatus.BehindBy = branch.TrackingDetails.BehindBy; } } return(repoStatus); }
private static IReadOnlyList <RepositoryContent> GetRepositoryContent <T>( T record ) { //https://developer.github.com/v3/repos/contents/ //The only part that's used by our test is the actual base64 contents //So most metadata arguments are faked (null) var content = new RepositoryContent( null, null, null, 0, ContentType.File, null, null, null, null, null, Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(record))), null, null ); return(new List <RepositoryContent>() { content }); }
static async Task Run() { string connectionString = await GetConnectionString(); RepositoryContent binary = await GetRecentNightlyBuild(); if (binary == null) { Trace.WriteLine("Repository has no new build."); return; } Trace.WriteLine("Last nightly build contains " + binary.Name); AzureExperimentManager manager = AzureExperimentManager.Open(connectionString); string lastNightlyExecutable = await GetLastNightlyExperiment(manager); if (lastNightlyExecutable == binary.Name) { Trace.WriteLine("No changes found since last nightly experiment."); return; } using (MemoryStream stream = new MemoryStream(binary.Size)) { await Download(binary, stream); stream.Position = 0; Trace.WriteLine("Opening an experiment manager..."); await SubmitExperiment(manager, stream, binary.Name); } }
private bool IsValid(RepositoryContent jenkinsContent) { if (jenkinsContent == null) { _logger.LogDebug("Rule {ruleClass} / {ruleName}, no {jenkinsFileName} found. Skipping.", nameof(HasNewestPtcsJenkinsLibRule), RuleName, JenkinsFileName); return(true); } var content = jenkinsContent.Content; var matches = _regex.Matches(content); var match = matches.OfType <Match>().FirstOrDefault(); if (match == null) { _logger.LogTrace("Rule {ruleClass} / {ruleName}, no jenkins-ptcs-library matches found. Skipping.", nameof(HasNewestPtcsJenkinsLibRule), RuleName); return(true); } var group = match.Groups.OfType <Group>().LastOrDefault(); if (group == null) { _logger.LogTrace("Rule {ruleClass} / {ruleName}, no jenkins-ptcs-library groups found. Skipping.", nameof(HasNewestPtcsJenkinsLibRule), RuleName); return(true); } return(group.Value == _expectedVersion); }
static async Task <RepositoryContent> GetRecentNightlyBuild() { Trace.WriteLine("Looking for most recent nightly build..."); var github = new GitHubClient(new ProductHeaderValue("Z3-Tests-Nightly-Runner")); var nightly = await github.Repository.Content.GetAllContents(Settings.GitHubOwner, Settings.GitHubBinariesRepository, Settings.GitHubBinariesNightlyFolder); var files = nightly.Select(f => Tuple.Create(f, regex.Match(f.Name))).Where(fm => fm.Item2.Success).ToArray(); if (files.Length == 0) { return(null); // no matching files found } if (files.Length == 1) { return(files[0].Item1); // single matching file } // Multiple matching files, should take the most recent DateTimeOffset max = DateTimeOffset.MinValue; RepositoryContent recent = null; foreach (var fm in files) { string sha = fm.Item2.Groups[Settings.RegexExecutableFileName_CommitGroup].Value; var commit = await github.Repository.Commit.Get(Settings.GitHubOwner, Settings.GitHubZ3Repository, sha); var date = commit.Commit.Committer.Date; if (date > max) { max = date; recent = fm.Item1; } } return(recent); }
public RepositoryContentWithCommitInfo([NotNull] RepositoryContent content, [CanBeNull] GitHubCommit commit = null, [CanBeNull] string message = null, [CanBeNull] DateTime?editTime = null) { Content = content; Commit = commit; _CommitMessage = message; LastEditTime = editTime; }
private async Task ExecuteCopyFileContent(string sourcePath, RepositoryContent sourceContent, PathGroupSpec copySpec, RepositoryReference sourceRepo, RepositoryReference targetRepo, CancellationToken cancelToken) { var targetPath = await GetTargetPath(sourceContent, copySpec, targetRepo) .ConfigureAwait(continueOnCapturedContext: false); if (cancelToken.IsCancellationRequested) { return; } RepositoryContentEntry targetEntry; try { targetEntry = await GetRepositoryContentEntry(targetRepo, targetPath) .ConfigureAwait(false); } catch (NotFoundException) { targetEntry = null; } var targetContent = targetEntry?.Leaf; bool copyCond = copySpec.Condition?.Evaluate( sourcePath, sourceRepo, sourceContent, targetPath, targetRepo, targetContent ) ?? true; if (!copyCond) { Logger.LogDebug($"Not copying path '{{{nameof(sourcePath)}}}' from {{{nameof(sourceRepo)}}} to '{{{nameof(targetPath)}}}' in {{{nameof(targetRepo)}}}. Condition of type {{conditionType}} evaluated {{conditionValue}}.", sourcePath, sourceRepo.ToLogString(), targetPath, targetRepo.ToLogString(), copySpec.Condition?.GetType(), copyCond); } }
public object Convert(object value, Type targetType, object parameter, string language) { RepositoryContent content = value as RepositoryContent; if (content == null) { return(String.Empty); } const int unknown = 0xE160, file = 0xE7C3, link = 0xE816, folder = 0xE8D5; if (content.Type.TryParse(out ContentType fileType)) { switch (fileType) { case ContentType.File: return(Regex.IsMatch(content.Name, @"[^.]+([.]\w+)") ? System.Convert.ToChar(file).ToString() : System.Convert.ToChar(unknown).ToString()); case ContentType.Dir: return(System.Convert.ToChar(folder).ToString()); default: return(System.Convert.ToChar(link).ToString()); } } return(System.Convert.ToChar(link).ToString()); }
public async Task <DownloadedGithubFile> DownloadFile(RepositoryContent content) { string name = content.Name; string url = content.DownloadUrl.OriginalString; string path = content.Path; return(await DownloadFile(name, url, path)); }
private Image ImageConverter(RepositoryContent content) { if (content.Name.Split('.')[1] != "jpg") { return(null); } using var fs = WebClient.OpenRead(new Uri(content.DownloadUrl)); return(new Bitmap(fs)); }
private void GrabbedHashes(Task <IReadOnlyList <RepositoryContent> > getHashFileTask) { RepositoryContent file = getHashFileTask.Result.FirstOrDefault(); using (var sha1 = new SHA1Managed()) { // TODO: How would local hash changes be handled when attempting to look for 'latest' changes } }
private string ConfigConverter(RepositoryContent content) { if (content is null) { return(String.Empty); } using var fs = WebClient.OpenRead(new Uri(content.DownloadUrl)); using var sr = new StreamReader(fs); return(sr.ReadToEnd()); }
public static ContentPage ToShortModel(this RepositoryContent repositoryContent, DateTime modifiedDate) { var retVal = new ContentPage(); retVal.Name = Path.GetFileNameWithoutExtension(repositoryContent.Name); retVal.ModifiedDate = modifiedDate; retVal.Language = GetLanguageFromFullPath(repositoryContent.Path); return(retVal); }
private void TestGithubButton_Click(object sender, RoutedEventArgs e) { string userName = this.GithubUserNameBox.Text; string repositoryName = this.GithubRepositoryNameBox.Text; GitHubClient githubClient = null; Repository repository = null; try { githubClient = new GitHubClient(new ProductHeaderValue(userName)); repository = githubClient.Repository.Get(userName, repositoryName).Result; } catch (Exception) { Core.BeepSound(); this.GithubResultBlock.Text = "깃허브 저장소 확인 실패"; return; } try { string[] imagePathSplit = Config.ImageFolderSubPath.Split('\\'); List <RepositoryContent> imageContents = githubClient.Repository.Content.GetAllContents(userName, repositoryName, imagePathSplit.First()).Result.ToList(); RepositoryContent dcconContent = imageContents.Find(x => x.Name == imagePathSplit.Last() && x.Type == "dir"); } catch (Exception) { Core.BeepSound(); this.GithubResultBlock.Text = "깃허브 이미지 저장경로 확인 실패"; return; } try { List <RepositoryContent> libraryContents = githubClient.Repository.Content.GetAllContents(userName, repositoryName, Config.DataFolderSubPath).Result.ToList(); RepositoryContent listContent = libraryContents.Find(x => x.Name == Config.JavaScriptFileName && x.Type == "file"); } catch (Exception) { Core.BeepSound(); this.GithubResultBlock.Text = "깃허브 데이터 저장경로 확인 실패"; return; } this.GithubUserNameBox.IsEnabled = false; this.GithubRepositoryNameBox.IsEnabled = false; this.GithubResultBlock.Text = "깃허브 저장소 테스트 성공"; this.CancelGithubButton.IsEnabled = true; this.TestGithubButton.IsEnabled = false; this.SaveGithubButton.IsEnabled = true; this.VisitGithubButton.IsEnabled = true; }
//------------------------------------------------- #region Constructors Region private DataBaseContent(RepositoryContent content, QString procedural) { Name = QString.Parse(WotoNameString.ToStrong(), false); Sha = QString.Parse(content.Sha.ToStrong(), false); Size = content.Size; TheEncoding = QString.Parse(content.Encoding.ToStrong(), false); EncodedContent = QString.Parse(content.EncodedContent.ToStrong()); Content = QString.Parse(content.Content.ToStrong(), true); Target = null; WotoGenerationProcedural = procedural; IsDeadCallBack = false; }
public override bool Evaluate(string sourcePath, RepositoryReference sourceRepo, RepositoryContent sourceContent, string targetPath, RepositoryReference targetRepo, RepositoryContent targetContent) { var cond = Condition?.Evaluate( sourcePath, sourceRepo, sourceContent, targetPath, targetRepo, targetContent ) ?? true; return(!cond); }
private async void ConnectToGitHub() { await Task.Run(() => { this.Dispatcher.Invoke(() => { this.uxMessage.Content = "Connecting with server"; }); this.gitHubClient = new GitHubClient(new ProductHeaderValue("fromtheword")); this.gitHubClient.SetRequestTimeout(new TimeSpan(0, 5, 0)); Task <Repository> repository = this.gitHubClient.Repository.Get("fromtheword", "Bibles-Application"); long reposirotyId = repository.Result.Id; IReadOnlyList <RepositoryContent> allContent = this.gitHubClient.Repository.Content.GetAllContents(reposirotyId).Result; foreach (RepositoryContent content in allContent.Where(t => t.Type == ContentType.Dir)) { if (!this.directoryNames.Contains(content.Name)) { continue; } TreeViewItemTool treeItem = null; this.Dispatcher.Invoke(() => { treeItem = new TreeViewItemTool { Header = content.Name, ResourceImageName = "Folder" }; this.uxDownloadTree.Items.Add(treeItem); }); this.LoadDirectoryContent(content, treeItem, reposirotyId); } RepositoryContent biblesRepository = allContent.First(n => n.Name == "Bibles.msi"); this.Dispatcher.Invoke(() => { TreeViewItemTool treeItem = new TreeViewItemTool { Header = "Bibles Install", IsCheckBox = true, Tag = biblesRepository }; this.uxDownloadTree.Items.Add(treeItem); }); }); }
public void RepoContentDrillNavigate(object sender, ItemClickEventArgs e) { RepositoryContent item = e.ClickedItem as RepositoryContentWithCommitInfo; if (item.Type == Octokit.ContentType.File) { SimpleIoc.Default.GetInstance <IAsyncNavigationService>().NavigateWithoutAnimations(typeof(FileContentView), Repository.FullName, new Tuple <Repository, string, string>(Repository, item.Path, SelectedBranch)); } else if (item.Type == Octokit.ContentType.Dir) { SimpleIoc.Default.GetInstance <IAsyncNavigationService>().NavigateWithoutAnimations(typeof(ContentView), Repository.FullName, new Tuple <Repository, string, string>(Repository, item.Path, SelectedBranch)); } }
public static ContentPage ToPageModel(this RepositoryContent repositoryContent) { var retVal = new ContentPage(); retVal.Name = Path.GetFileNameWithoutExtension(repositoryContent.Name); if (!string.IsNullOrEmpty(repositoryContent.Content)) { retVal.ByteContent = Encoding.UTF8.GetBytes(repositoryContent.Content); } retVal.Language = GetLanguageFromFullPath(repositoryContent.Path); return(retVal); }
public async Task DeleteFileAsync(long repositoryId, string path, string fileName) { IReadOnlyList <RepositoryContent> contents = await _githubClient.Repository.Content.GetAllContents(repositoryId, Path.Combine(path, fileName)); RepositoryContent repositoryContent = contents.First(); await _githubClient.Repository.Content.DeleteFile( repositoryId, Path.Combine(path, fileName), new DeleteFileRequest($"Delete {fileName}", repositoryContent.Sha) ); }
public async Task DeleteFileAsync(string path, string fileName) { IReadOnlyList <RepositoryContent> contents = await _client.Repository.Content.GetAllContents(_githubSetting.RepositoryID, Path.Combine(path, fileName)); RepositoryContent repositoryContent = contents.First(); await _client.Repository.Content.DeleteFile( _githubSetting.RepositoryID, Path.Combine(path, fileName), new DeleteFileRequest($"Delete {fileName}", repositoryContent.Sha, _githubSetting.Branch) ); }
private static async Task Download(RepositoryContent binary, Stream stream) { Trace.WriteLine(string.Format("Downloading new nightly build from {0} ({1:F2} MB)...", binary.DownloadUrl, binary.Size / 1024.0 / 1024.0)); HttpWebRequest request = WebRequest.CreateHttp(binary.DownloadUrl); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) using (Stream respStream = response.GetResponseStream()) { await respStream.CopyToAsync(stream); } }
public async Task UpdateFileAsync(long repositoryId, string path, string fileName, string content) { IReadOnlyList <RepositoryContent> contents = await _githubClient.Repository.Content.GetAllContents(repositoryId, Path.Combine(path, fileName)); RepositoryContent repositoryContent = contents.First(); await _githubClient.Repository.Content.UpdateFile( repositoryId, Path.Combine(path, fileName), new($"Update {fileName}", content, repositoryContent.Sha, "main") ); }
public static async Task <RepositoryContent> LatestBlogpost() { if (blogpost == null) { blogpost = ( await Client.Repository.Content.GetAllContentsByRef( "mat1jaczyyy", "apollo-studio-blog", (await Client.Repository.Content.GetAllContents("mat1jaczyyy", "apollo-studio-blog")).Last().Name, "master" ) ).Last(); } return(blogpost); }
public static GithubFile FromRepositoryContent(RepositoryContent file) { GithubFile item = new GithubFile(); item.Name = file.Name; item.Path = file.Path; item.Sha = file.Sha; item.IsDirectory = (file.Type == ContentType.Dir); if (!item.IsDirectory) { item.DownloadUrl = file.DownloadUrl.OriginalString; } string[] split = file.Name.Split('.'); item.Extension = split[split.Length - 1]; return(item); }
/// <summary> /// Gives the complete repository status /// </summary> /// <param name="owner">The owner of the repo, org or user</param> /// <param name="repository">The name of repository</param> /// <returns>The repository status</returns> public RepoStatus RepositoryStatus(string owner, string repository) { RepoStatus repoStatus = new RepoStatus(); repoStatus.ContentStatus = new List <RepositoryContent>(); string localServiceRepoFolder = _settings.GetServicePath(owner, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)); using (var repo = new Repository(localServiceRepoFolder)) { var watch = System.Diagnostics.Stopwatch.StartNew(); RepositoryStatus status = repo.RetrieveStatus(new LibGit2Sharp.StatusOptions()); watch.Stop(); _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "retrieverepostatusentries - {0} ", watch.ElapsedMilliseconds); watch = System.Diagnostics.Stopwatch.StartNew(); foreach (StatusEntry item in status) { RepositoryContent content = new RepositoryContent(); content.FilePath = item.FilePath; content.FileStatus = (AltinnCore.Common.Enums.FileStatus)(int) item.State; if (content.FileStatus == Enums.FileStatus.Conflicted) { repoStatus.RepositoryStatus = Enums.RepositoryStatus.MergeConflict; repoStatus.HasMergeConflict = true; } repoStatus.ContentStatus.Add(content); } watch.Stop(); _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "parsestatusentries - {0}", watch.ElapsedMilliseconds); watch = System.Diagnostics.Stopwatch.StartNew(); Branch branch = repo.Branches.FirstOrDefault(b => b.IsTracking == true); if (branch != null) { repoStatus.AheadBy = branch.TrackingDetails.AheadBy; repoStatus.BehindBy = branch.TrackingDetails.BehindBy; } watch.Stop(); _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "branch details - {0}", watch.ElapsedMilliseconds); } return(repoStatus); }