private static void DeleteMyProjects(PrivateUserDto user, string projectName) { var userName = user.Username; var api = new ProjectsApi(); api.DeleteProject(userName, projectName); }
/// <summary> /// Get a project by current user and name. If not found, then create a new project. /// </summary> /// <param name="user"></param> /// <param name="projectName"></param> /// <returns></returns> public static ProjectDto GetAProject(PrivateUserDto user, string projectName) { var api = new ProjectsApi(); try { var d = api.GetProject(user.Username, projectName); return(d); } catch (ApiException e) { // Project not found if (e.ErrorCode == 404) { var ifPublic = projectName == "unnamed"; var res = api.CreateProject(user.Username, new PatchProjectDto(projectName, _public: ifPublic)); return(GetAProject(user, projectName)); } throw e; } //var d = GetProjects(user).FirstOrDefault(_ => _.Name == projectName); //return d; }
private static IEnumerable <ProjectDto> GetProjects(PrivateUserDto user) { var api = new ProjectsApi(); var d = api.ListProjects(_public: true, owner: new List <string>() { user.Username }); //var projectNames = d.Select(_ => $"<{_.Id}> {_.Name} ({_.Owner.Name})"); return(d); }
private static ProjectDto CreateAProject(PrivateUserDto user) { var userName = user.Username; //var userName = "******"; var api = new ProjectsApi(); var name = "My new project " + Guid.NewGuid().ToString().Substring(0, 5); var proj = new PatchProjectDto(name, "A new project from GH"); Console.WriteLine("---------------------------------------"); Console.WriteLine($"Creating project: {name}"); var res = api.CreateProject(userName, proj); Console.WriteLine($"New project id: {res.Id}"); Console.WriteLine(res.Message); var newProj = Helper.GetAProject(user, name); return(newProj); }