public ActionResult Delete(RepositoryDetailModel model) { if (model != null) { var repo = RepositoryRepository.GetRepository(model.Id); string path = Path.Combine(UserConfiguration.Current.Repositories, repo.Name); if (Directory.Exists(path)) { DeleteFileSystemInfo(new DirectoryInfo(path)); } RepositoryRepository.Delete(repo.Id); TempData["DeleteSuccess"] = true; } return(RedirectToAction("Index")); }
private IEnumerable <RepositoryDetailModel> GetIndexModel() { IEnumerable <RepositoryModel> repositoryModels; if (User.IsInRole(Definitions.Roles.Administrator)) { repositoryModels = RepositoryRepository.GetAllRepositories(); } else { var userTeams = TeamRepository.GetTeams(User.Identity.Name).Select(i => i.Name).ToArray(); repositoryModels = RepositoryRepository.GetPermittedRepositories(User.Identity.Name, userTeams); } return(repositoryModels.Select(ConvertRepositoryModel).ToList()); }
public ActionResult Edit(RepositoryDetailModel model) { if (ModelState.IsValid) { if (model.Administrators.Contains(User.Identity.Name.ToLowerInvariant())) { RepositoryRepository.Update(ConvertRepositoryDetailModel(model)); ViewBag.UpdateSuccess = true; } else { ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself); } } PopulateEditData(); return(View(model)); }
public ActionResult Blob(Guid id, string encodedName, string encodedPath) { ViewBag.ID = id; var repo = RepositoryRepository.GetRepository(id); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); string referenceName; var model = browser.BrowseBlob(name, path, out referenceName); PopulateBranchesData(browser, referenceName); PopulateAddressBarData(path); return(View(model)); } }
/// <summary> /// Runs prior to the work being done. /// </summary> protected override void PreExecute() { WellKnownError = new WellKnownErrors(); TranscriptionRepository = new TranscriptionRepository(); RepositoryRepository = new RepositoryRepository(); CollectionRepository = new CollectionRepository(); SubseryRepository = new SubseryRepository(); SubjectRepository = new SubjectRepository(); KeywordRepository = new KeywordRepository(); PredefineUserRepository = new PredefineUserRepository(); AudioEquipmentUsedRepository = new AudioEquipmentUsedRepository(); VideoEquipmentUsedRepository = new VideoEquipmentUsedRepository(); UserTypeRepository = new UserTypeRepository(); WellKnownError.Value = WellKnownError.NoError; }
public ActionResult Edit(RepositoryDetailModel model) { if (ModelState.IsValid) { if (model.Administrators.Contains(User.Id(), StringComparer.OrdinalIgnoreCase)) { RepositoryRepository.Update(ConvertRepositoryDetailModel(model)); ViewBag.UpdateSuccess = true; } else { ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself); } } PopulateEditData(); return(View(model)); }
public ActionResult History(Guid id, string encodedPath, string encodedName) { ViewBag.ID = id; ViewBag.ShowShortMessageOnly = true; var repo = RepositoryRepository.GetRepository(id); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { var path = PathEncoder.Decode(encodedPath); var name = PathEncoder.Decode(encodedName); string referenceName; var commits = browser.GetHistory(path, name, out referenceName); return(View(new RepositoryCommitsModel { Commits = commits, Name = repo.Name })); } }
public ActionResult Edit(RepositoryDetailModel model) { if (ModelState.IsValid) { if (model.PostedSelectedAdministrators.Contains(User.Id())) { RepositoryRepository.Update(ConvertRepositoryDetailModel(model)); ViewBag.UpdateSuccess = true; } else { ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself); } } PopulateCheckboxListData(ref model); return(View(model)); }
public ActionResult Tree(Guid id, string encodedName, string encodedPath) { bool includeDetails = Request.IsAjaxRequest(); ViewBag.ID = id; var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); var repo = RepositoryRepository.GetRepository(id); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { string referenceName; var files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList(); var readme = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase)); string readmeTxt = string.Empty; if (readme != null) { string refereceName; var blob = browser.BrowseBlob(name, readme.Path, out refereceName); readmeTxt = blob.Text; } var model = new RepositoryTreeModel { Name = repo.Name, Branch = name ?? referenceName, Path = path, Readme = readmeTxt, Logo = new RepositoryLogoDetailModel(repo.Logo), Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name) }; if (includeDetails) { return(Json(model, JsonRequestBehavior.AllowGet)); } else { PopulateBranchesData(browser, referenceName); PopulateAddressBarData(path); return(View(model)); } } }
public ActionResult Clone(string id, RepositoryDetailModel model) { if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfiguration.Current.AllowUserRepositoryCreation) { return(RedirectToAction("Unauthorized", "Home")); } if (model != null && !String.IsNullOrEmpty(model.Name)) { model.Name = Regex.Replace(model.Name, @"\s", ""); } if (String.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure); } else if (ModelState.IsValid) { if (RepositoryRepository.Create(ConvertRepositoryDetailModel(model))) { string targetRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, model.Name); if (!Directory.Exists(targetRepositoryPath)) { string sourceRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, id); LibGit2Sharp.Repository.Clone(sourceRepositoryPath, targetRepositoryPath, true, false); TempData["CloneSuccess"] = true; return(RedirectToAction("Index")); } else { RepositoryRepository.Delete(model.Name); ModelState.AddModelError("", Resources.Repository_Create_DirectoryExists); } } else { ModelState.AddModelError("", Resources.Repository_Create_Failure); } } ViewBag.ID = id; PopulateEditData(); return(View(model)); }
public ActionResult Create(RepositoryDetailModel model) { if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfigurationManager.AllowUserRepositoryCreation) { return(RedirectToAction("Unauthorized", "Home")); } if (model != null && !String.IsNullOrEmpty(model.Name)) { model.Name = Regex.Replace(model.Name, @"\s", ""); } if (String.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure); } else if (ModelState.IsValid) { if (RepositoryRepository.Create(ConvertRepositoryDetailModel(model))) { string path = Path.Combine(UserConfigurationManager.Repositories, model.Name); if (!Directory.Exists(path)) { using (var repository = new GitSharp.Core.Repository(new DirectoryInfo(path))) { repository.Create(true); } TempData["CreateSuccess"] = true; return(RedirectToAction("Index")); } else { RepositoryRepository.Delete(model.Name); ModelState.AddModelError("", Resources.Repository_Create_DirectoryExists); } } else { ModelState.AddModelError("", Resources.Repository_Create_Failure); } } PopulateEditData(); return(View(model)); }
public ActionResult Create(RepositoryDetailModel model) { if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfiguration.Current.AllowUserRepositoryCreation) { return(RedirectToAction("Unauthorized", "Home")); } if (model != null && !String.IsNullOrEmpty(model.Name)) { model.Name = Regex.Replace(model.Name, @"\s", ""); } if (model != null && String.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure); } else if (ModelState.IsValid) { var repo_model = ConvertRepositoryDetailModel(model); if (RepositoryRepository.Create(repo_model)) { string path = Path.Combine(UserConfiguration.Current.Repositories, model.Name); if (!Directory.Exists(path)) { LibGit2Sharp.Repository.Init(path, true); TempData["CreateSuccess"] = true; TempData["SuccessfullyCreatedRepositoryName"] = model.Name; TempData["SuccessfullyCreatedRepositoryId"] = repo_model.Id; return(RedirectToAction("Index")); } else { RepositoryRepository.Delete(model.Id); ModelState.AddModelError("", Resources.Repository_Create_DirectoryExists); } } else { ModelState.AddModelError("", Resources.Repository_Create_Failure); } } PopulateCheckboxListData(ref model); return(View(model)); }
public ActionResult Commit(Guid id, string commit) { ViewBag.ID = id; ViewBag.ShowShortMessageOnly = false; var repo = RepositoryRepository.GetRepository(id); ViewBag.ID = id; ViewBag.Name = repo.Name; ViewBag.GitUrl = GitUrl(repo.Name); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { string referenceName; var model = browser.GetCommitDetail(commit, out referenceName); PopulateBranchesData(browser, referenceName); model.Name = repo.Name; model.Logo = new RepositoryLogoDetailModel(repo.Logo); return(View(model)); } }
public ActionResult Detail(Guid id) { ViewBag.ID = id; var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id)); if (model != null) { model.IsCurrentUserAdministrator = User.IsInRole(Definitions.Roles.Administrator) || RepositoryPermissionService.IsRepositoryAdministrator(User.Id(), model.Id); SetGitUrls(model); } using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name))) { string defaultReferenceName; browser.BrowseTree(null, null, out defaultReferenceName); RouteData.Values.Add("encodedName", defaultReferenceName); } return(View(model)); }
private Guid GetRepoId(AuthorizationContext filterContext) { if (filterContext.Controller.ControllerContext.RouteData.Values.ContainsKey("id")) { Guid result; if (Guid.TryParse(filterContext.Controller.ControllerContext.RouteData.Values["id"].ToString(), out result)) { return(result); } else { return(Guid.Empty); } } else { return(RepositoryRepository.GetRepository(filterContext.Controller.ControllerContext.RouteData.Values["repositoryName"].ToString()).Id); } }
public ActionResult GitLfsBasicTransferDownload(string repositoryName, string oid) { bool authorized = RepositoryPermissionService.HasPermission(User.Id(), RepositoryRepository.GetRepository(repositoryName).Id, RepositoryAccessLevel.Pull); if (!authorized) { Response.StatusCode = 403; return(Content( Newtonsoft.Json.JsonConvert.SerializeObject(new BatchApiErrorResponse() { Message = "You do not have permission to PULL (LFS download)." }) , GitLfsConsts.GIT_LFS_CONTENT_TYPE)); } Stream readStream = StorageProvider.GetReadStream(LfsOperationNames.DOWNLOAD, repositoryName, oid); return(File(readStream, "application/octet-stream")); }
public ActionResult Graph(Guid id) { ViewBag.ID = id; var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id), User); if (model != null) { model.IsCurrentUserAdministrator = RepositoryPermissionService.HasPermission(User.Id(), model.Id, RepositoryAccessLevel.Administer); SetGitUrls(model); } using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name))) { string defaultReferenceName; browser.BrowseTree(null, null, out defaultReferenceName); RouteData.Values.Add("encodedName", defaultReferenceName); } return(View(model)); }
public ActionResult Detail(string id) { ViewBag.ID = id; if (!String.IsNullOrEmpty(id)) { var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id)); if (model != null) { model.IsCurrentUserAdministrator = RepositoryPermissionService.IsRepositoryAdministrator(User.Identity.Name, id); } using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id))) { string defaultReferenceName; browser.BrowseTree(null, null, out defaultReferenceName); RouteData.Values.Add("encodedName", defaultReferenceName); } return(View(model)); } return(View()); }
/// <summary> Creates a new <see cref="GitLabClient" /> instance. </summary> /// <param name="hostUri"> The GitLab server to connect to. </param> /// <param name="privateToken"> The private token to use when making requests to the GitLab API. </param> public GitLabClient(Uri hostUri, string privateToken = null) { if (hostUri == null) { throw new ArgumentNullException(nameof(hostUri)); } var baseUri = new Uri(hostUri, ApiPath); _authenticator = new PrivateTokenAuthenticator(privateToken); var clientFactory = new ClientFactory(baseUri, _authenticator); var requestFactory = new RequestFactory(clientFactory); Branches = new BranchRepository(requestFactory); Builds = new BuildRepository(requestFactory); BuildTriggers = new BuildTriggerRepository(requestFactory); BuildVariables = new BuildVariableRepository(requestFactory); Commits = new CommitRepository(requestFactory); DeployKeys = new DeployKeyRepository(requestFactory); Emails = new EmailRepository(requestFactory); Files = new FileRepository(requestFactory); GitLabLicense = new GitLabLicenseRepository(requestFactory); GitLabSettings = new GitLabSettingsRepository(requestFactory); Issues = new IssueRepository(requestFactory); Keys = new KeyRepository(requestFactory); Labels = new LabelRepository(requestFactory); Licenses = new LicenseRepository(requestFactory); MergeRequests = new MergeRequestRepository(requestFactory); Milestones = new MilestoneRepository(requestFactory); Namespaces = new NamespaceRepository(requestFactory); ProjectSnippets = new ProjectSnippetRepository(requestFactory); Repositories = new RepositoryRepository(requestFactory); Runners = new RunnerRepository(requestFactory); Session = new SessionRepository(requestFactory); SystemHooks = new SystemHookRepository(requestFactory); Tags = new TagRepository(requestFactory); Users = new UserRepository(requestFactory); Projects = new ProjectRepository(requestFactory); ProjectMembers = new ProjectMemberRepository(requestFactory); GroupMembers = new GroupMemberRepository(requestFactory); }
public ActionResult Commits(Guid id, string encodedName, int page = 1) { page = page >= 1 ? page : 1; ViewBag.ID = id; ViewBag.ShowShortMessageOnly = true; var repo = RepositoryRepository.GetRepository(id); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { var name = PathEncoder.Decode(encodedName); string referenceName; int totalCount; var commits = browser.GetCommits(name, page, 10, out referenceName, out totalCount); PopulateBranchesData(browser, referenceName); ViewBag.TotalCount = totalCount; return(View(new RepositoryCommitsModel { Commits = commits, Name = repo.Name })); } }
public ActionResult Blame(Guid id, string encodedName, string encodedPath) { ViewBag.ShowShortMessageOnly = true; var repo = RepositoryRepository.GetRepository(id); ViewBag.ID = id; ViewBag.Name = repo.Name; ViewBag.GitUrl = GitUrl(repo.Name); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); string referenceName; var model = browser.GetBlame(name, path, out referenceName); model.Logo = new RepositoryLogoDetailModel(repo.Logo); PopulateBranchesData(browser, referenceName); PopulateAddressBarData(path); return(View(model)); } }
private void PopulateCheckboxListData(ref RepositoryDetailModel model) { model = model.Id != Guid.Empty ? ConvertRepositoryModel(RepositoryRepository.GetRepository(model.Id), User) : model; model.AllAdministrators = MembershipService.GetAllUsers().ToArray(); model.AllUsers = MembershipService.GetAllUsers().ToArray(); model.AllTeams = TeamRepository.GetAllTeams().ToArray(); if (model.PostedSelectedUsers != null && model.PostedSelectedUsers.Any()) { model.Users = model.PostedSelectedUsers.Select(x => MembershipService.GetUserModel(x)).ToArray(); } if (model.PostedSelectedTeams != null && model.PostedSelectedTeams.Any()) { model.Teams = model.PostedSelectedTeams.Select(x => TeamRepository.GetTeam(x)).ToArray(); } if (model.PostedSelectedAdministrators != null && model.PostedSelectedAdministrators.Any()) { model.Administrators = model.PostedSelectedAdministrators.Select(x => MembershipService.GetUserModel(x)).ToArray(); } model.PostedSelectedAdministrators = new Guid[0]; model.PostedSelectedUsers = new Guid[0]; model.PostedSelectedTeams = new Guid[0]; }
public void SetUp() { _privateRepository = ConfigurationManager.AppSettings["privaterepo"]; _repoApi = new RepositoryRepository(GetProxyWithAuthProvider()); }
public async Task Compare_ToIsNull_ThrowsArgumentNullException() { var sut = new RepositoryRepository(_requestFactory); await Assert.ThrowsAsync <ArgumentNullException>(() => sut.Compare(0, "from", null)); }
public ActionResult Commits(Guid id, string encodedName, int?page = null) { page = page >= 1 ? page : 1; ViewBag.ShowShortMessageOnly = true; var repo = RepositoryRepository.GetRepository(id); ViewBag.ID = id; ViewBag.Name = repo.Name; ViewBag.GitUrl = GitUrl(repo.Name); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { var name = PathEncoder.Decode(encodedName); string referenceName; int totalCount; var commits = browser.GetCommits(name, page.Value, 10, out referenceName, out totalCount); PopulateBranchesData(browser, referenceName); ViewBag.TotalCount = totalCount; var linksreg = repo.LinksUseGlobal ? UserConfiguration.Current.LinksRegex : repo.LinksRegex; var linksurl = repo.LinksUseGlobal ? UserConfiguration.Current.LinksUrl : repo.LinksUrl; foreach (var commit in commits) { var links = new List <string>(); if (!string.IsNullOrEmpty(linksreg)) { try { var matches = Regex.Matches(commit.Message, linksreg); if (matches.Count > 0) { foreach (Match match in matches) { IEnumerable <Group> groups = match.Groups.Cast <Group>(); var link = ""; try { var m = groups.Select(x => x.ToString()).ToArray(); link = string.Format(linksurl, m); } catch (FormatException e) { link = "An error occured while trying to format the link. Exception: " + e.Message; } links.Add(link); } } } catch (ArgumentException e) { links.Add("An error occured while trying to match the regualar expression. Error: " + e.Message); } } commit.Links = links; } return(View(new RepositoryCommitsModel { Commits = commits, Name = repo.Name, Logo = new RepositoryLogoDetailModel(repo.Logo) })); } }
public async Task GetFileContent_ShaIsNull_ThrowsArgumentNullException() { var sut = new RepositoryRepository(_requestFactory); await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetFileContent(0, null, "filePath")); }
public BuildDefinitionUpdater(BuildDefinitionRepository buildDefinitionRepository, RequestData requestData, ProjectRepository projectRepository, UpdateStatusRepository updateStatusRepository, RepositoryRepository repositoryRepository, ILogger <BuildDefinitionUpdater> logger) : base(logger) { this.buildDefinitionRepository = buildDefinitionRepository; this.requestData = requestData; this.projectRepository = projectRepository; this.updateStatusRepository = updateStatusRepository; this.repositoryRepository = repositoryRepository; }
public RepositoryUpdater(ProjectRepository projectRepository, RequestData requestData, RepositoryRepository repositoryRepository, UpdateStatusRepository updateStatusRepository, ILogger <RepositoryUpdater> logger) : base(logger) { this.projectRepository = projectRepository; this.requestData = requestData; this.repositoryRepository = repositoryRepository; this.updateStatusRepository = updateStatusRepository; }
public ActionResult Clone(Guid id, RepositoryDetailModel model) { if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfiguration.Current.AllowUserRepositoryCreation) { return(RedirectToAction("Unauthorized", "Home")); } if (model != null && !String.IsNullOrEmpty(model.Name)) { model.Name = Regex.Replace(model.Name, @"\s", ""); } if (model != null && String.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure); } else if (ModelState.IsValid) { var repo_model = ConvertRepositoryDetailModel(model); if (RepositoryRepository.Create(repo_model)) { string targetRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, model.Name); if (!Directory.Exists(targetRepositoryPath)) { var source_repo = RepositoryRepository.GetRepository(id); string sourceRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, source_repo.Name); LibGit2Sharp.CloneOptions options = new LibGit2Sharp.CloneOptions() { IsBare = true, Checkout = false }; LibGit2Sharp.Repository.Clone(sourceRepositoryPath, targetRepositoryPath, options); using (var repo = new LibGit2Sharp.Repository(targetRepositoryPath)) { if (repo.Network.Remotes.Any(r => r.Name == "origin")) { repo.Network.Remotes.Remove("origin"); } } TempData["CloneSuccess"] = true; return(RedirectToAction("Index")); } else { RepositoryRepository.Delete(model.Id); ModelState.AddModelError("", Resources.Repository_Create_DirectoryExists); } } else { ModelState.AddModelError("", Resources.Repository_Create_Failure); } } ViewBag.ID = id; PopulateCheckboxListData(ref model); return(View(model)); }
public ActionResult Delete(Guid id) { return(View(ConvertRepositoryModel(RepositoryRepository.GetRepository(id)))); }