Exemple #1
0
        private static async Task TransferIssues(string githubRepo)
        {
            var issues = await GitlabApi.GetProjectIssues();

            // var issues = new JArray(await GitlabApi.GetIssue(80));

            int count = 1, tot = issues.Count;

            foreach (var issue in issues)
            {
                Console.Write($"\rissue {count} of {tot}");
                var issueId  = issue["iid"].ToObject <int>();
                var comments = await GitlabApi.GetIssueComments(issueId);

                var githubId = await GitHubApi.CreateIssue(new
                {
                    Title = issue["title"].Value <string>(),
                    Body  =
                        $"{issue["description"].Value<string>()}\n\n > Created By: {issue["author"]["name"].Value<string>()}",
                    Labels = issue["labels"].ToObject <string[]>()
                }, githubRepo);

                foreach (var comment in comments)
                {
                    await GitHubApi.AddCommentToIssue(new
                    {
                        Body = $@"{comment["body"].ToObject<string>()}

> Created By: {comment["author"]["name"].ToObject<string>()}
> Created At: {DateTime.Parse(comment["created_at"].ToObject<string>()):MM/dd/yyyy hh:mm tt}"
                    }, githubRepo, githubId);
Exemple #2
0
 public JobContextResolver(IOptions <GitLabPagesOptions> options,
                           GitlabApi api,
                           IMemoryCache cache)
 {
     _api     = api;
     _options = options.Value;
     _cache   = cache;
 }
Exemple #3
0
 public Jobs(
     GitlabApi api,
     IProject project,
     IPipeline pipeline)
 {
     _api      = api;
     _project  = project;
     _pipeline = pipeline;
 }
Exemple #4
0
 public Job(
     GitlabApi api,
     IProject project,
     IPipeline pipeline,
     int jobId)
 {
     _api      = api;
     _project  = project;
     _pipeline = pipeline;
     JobId     = jobId;
 }
 public JobArtifactsMiddleware(RequestDelegate next,
                               IApplicationBuilder app,
                               GitlabApi api,
                               IJobArtifactCache jobArtifactCache,
                               IOptions <GitLabPagesOptions> options)
 {
     _next             = next;
     _app              = app;
     _api              = api;
     _jobArtifactCache = jobArtifactCache;
     _options          = options.Value;
 }
Exemple #6
0
        public static (Project project, Repo repo) ImportProject(User me, string originId)
        {
            var tokenModel = me.ServiceAccessToken(ServiceType.GitLab);
            var client     = new GitLabClient(tokenModel.access_token);

            client.SetAuthorizedUser();

            if (tokenModel.origin_user_id == "")
            {
                GitLabUserUtils.UpdateOriginUserId(me);
            }

            var gitLabProject = GitlabApi.GetPublicProject(originId);

            if (gitLabProject == null)
            {
                return(null, null);
            }

            Repo repository = RepoRepository.CreateAndGet(
                me,
                gitLabProject.Value <string>("name"),
                gitLabProject.Value <string>("web_url"),
                RepoServiceType.GitLab,
                gitLabProject.Value <string>("id")
                );

            var originUserId = tokenModel.origin_user_id;

            User creator = null;

            var projectUsers = GitlabApi.GetProjectUsers(originId);

            foreach (var projectUser in projectUsers.Children())
            {
                if (originUserId == projectUser.Value <string>("id"))
                {
                    creator = me;
                    break;
                }
            }

            var project = ProjectRepository.FindOrCreate(repository.title, creator, repository);

            project.UpdateCol("description", gitLabProject.Value <string>("description"));

            return(project, repository);
        }
Exemple #7
0
        protected override void Setup(bool usePrivateRepo)
        {
            // re-use test repo for Api tests
            var s = new ConfigSource();

            s.Hoster    = "gitlab";
            s.Type      = "user";
            s.Name      = this.GetUserName(usePrivateRepo);
            s.AuthName  = TestHelper.EnvVar(prefix, "Name");
            s.Password  = TestHelper.EnvVar(prefix, "PW");
            this.source = s;

            var config = new Config();

            config.Sources.Add(s);

            var context = new FakeContext();

            context.Config = config;

            var factory = new FakeScmFactory();

            factory.Register(ScmType.Git, new GitScm(new FileSystemHelper(), context));

            var api      = new GitlabApi(new HttpRequest(), factory);
            var repoList = api.GetRepositoryList(this.source);

            this.repo = repoList.Find(r => r.ShortName == this.GetRepoName(usePrivateRepo));

            this.scm = new GitScm(new FileSystemHelper(), context);
            Assert.True(this.scm.IsOnThisComputer());

            var scmfactory = new FakeScmFactory();

            scmfactory.Register(ScmType.Git, this.scm);
            this.sut = new GitlabBackup(scmfactory);
        }
 public Pipeline(IProject project, int pipelineId, GitlabApi api)
 {
     _project   = project;
     _api       = api;
     PipelineId = pipelineId;
 }
 public Pipelines(IProject project, GitlabApi api)
 {
     _project = project;
     _api     = api;
 }
 public Projects(GitlabApi api)
 {
     _api = api;
 }
Exemple #11
0
        public ImportRepoController()
        {
            Post("/api/v1/repository/import", _ => {
                var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
                    new ShouldHaveParameters(new[] { "service_type", "origin_id" }),
                    new ShouldBeCorrectEnumValue("service_type", typeof(RepoServiceType))
                }, true);
                if (errors.Count > 0)
                {
                    return(HttpResponse.Errors(errors));
                }

                var originId = GetRequestStr("origin_id");

                RepoServiceType serviceType =
                    (RepoServiceType)GetRequestEnum("service_type", typeof(RepoServiceType));

                var existingRepo = RepoRepository.Find(originId, serviceType);

                if (existingRepo != null)
                {
                    return(HttpResponse.Error(HttpStatusCode.UnprocessableEntity, "Project is already imported",
                                              new JObject()
                    {
                        ["project"] = new ProjectTransformer().Transform(existingRepo.Project()),
                    }));
                }

                if (serviceType == RepoServiceType.GitHub && !GitHubRepositoriesUtils.IfRepoExists(originId))
                {
                    return(HttpResponse.Error(
                               HttpStatusCode.NotFound, "GitHub repository with this id does not exist"
                               ));
                }

                if (serviceType == RepoServiceType.GitLab && !GitlabApi.IfRepoExists(originId))
                {
                    return(HttpResponse.Error(
                               HttpStatusCode.NotFound, "GitLab repository with this id does not exist"
                               ));
                }

                var me = UserRepository.Find(CurrentRequest.UserId);

                (ProjectModel project, DL.Model.Repo.Repo repo)result = (null, null);

                switch (serviceType)
                {
                case RepoServiceType.GitHub:
                    result = GitHubRepositoriesUtils.ImportProject(me, originId);
                    break;

                case RepoServiceType.GitLab:
                    result = GitLabRepositoriesUtils.ImportProject(me, originId);
                    break;
                }

                if (result.project == null || result.repo == null)
                {
                    return(HttpResponse.Error(HttpStatusCode.BadRequest, "Cannot import target project"));
                }

                return(HttpResponse.Data(new JObject()
                {
                    ["project"] = new ProjectTransformer().Transform(result.project),
                    ["repository"] = new RepoTransformer().Transform(result.repo)
                }));
            });