Ejemplo n.º 1
0
        public bool TryGetRepositoryInfo(HttpRequest request, JObject payload, out RepositoryInfo repositoryInfo)
        {
            repositoryInfo = null;
            if (request.UserAgent != null &&
                request.UserAgent.StartsWith("Bitbucket", StringComparison.OrdinalIgnoreCase))
            {
                repositoryInfo = GetRepositoryInfo(request, payload);
            }

            return repositoryInfo != null;
        }
Ejemplo n.º 2
0
        public bool TryGetRepositoryInfo(HttpRequest request, JObject payload, out RepositoryInfo repositoryInfo)
        {
            // Look for the generic format
            // { url: "", branch: "", deployer: "", oldRef: "", newRef: "" }
            repositoryInfo = new RepositoryInfo
            {
                RepositoryUrl = payload.Value<string>("url"),
                Deployer = payload.Value<string>("deployer"),
                OldRef = payload.Value<string>("oldRef"),
                NewRef = payload.Value<string>("newRef")
            };

            return repositoryInfo.IsValid();
        }
Ejemplo n.º 3
0
        public override bool TryGetRepositoryInfo(HttpRequest request, JObject payload, out RepositoryInfo repositoryInfo)
        {
            repositoryInfo = null;
            if (request.Headers["X-Github-Event"] != null)
            {
                repositoryInfo = GetRepositoryInfo(request, payload);
                if (repositoryInfo == null)
                {
                    throw new FormatException(Resources.Error_UnsupportedFormat);
                }
            }

            return repositoryInfo != null;
        }
Ejemplo n.º 4
0
        protected virtual RepositoryInfo GetRepositoryInfo(HttpRequest request, JObject payload)
        {
            JObject repository = payload.Value<JObject>("repository");
            if (repository == null)
            {
                return null;
            }

            var info = new RepositoryInfo();

            // github format
            // { repository: { url: "https//...", private: False }, ref: "", before: "", after: "" }
            info.RepositoryUrl = repository.Value<string>("url");
            info.IsPrivate = repository.Value<bool>("private");

            // The format of ref is refs/something/something else
            // For master it's normally refs/head/master
            string @ref = payload.Value<string>("ref");

            if (String.IsNullOrEmpty(@ref))
            {
                return null;
            }

            info.Deployer = GetDeployer(request);
            info.OldRef = payload.Value<string>("before");
            info.NewRef = payload.Value<string>("after");

            // private repo, use SSH
            if (info.IsPrivate)
            {
                Uri uri = new Uri(info.RepositoryUrl);
                if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    info.Host = "git@" + uri.Host;
                    info.RepositoryUrl = info.Host + ":" + uri.AbsolutePath.TrimStart('/');
                    info.UseSSH = true;
                }
            }

            return info;
        }
Ejemplo n.º 5
0
        private RepositoryInfo GetRepositoryInfo(HttpRequest request, JObject payload)
        {
            // bitbucket format
            // { repository: { absolute_url: "/a/b", is_private: true }, canon_url: "https//..." }
            var repository = payload.Value<JObject>("repository");

            var info = new RepositoryInfo();
            string server = payload.Value<string>("canon_url");     // e.g. https://bitbucket.org
            string path = repository.Value<string>("absolute_url"); // e.g. /davidebbo/testrepo/

            // Combine them to get the full URL
            info.RepositoryUrl = server + path;
            info.IsPrivate = repository.Value<bool>("is_private");

            // We don't get any refs from bitbucket, so write dummy string (we ignore it later anyway)
            info.OldRef = "dummy";

            // When there are no commits, set the new ref to an all-zero string to cause the logic in
            // GitDeploymentRepository.GetReceiveInfo ignore the push
            var commits = payload.Value<JArray>("commits");
            info.NewRef = commits.Count == 0 ? "000" : "dummy";

            info.Deployer = request.UserAgent;

            // private repo, use SSH
            if (info.IsPrivate)
            {
                Uri uri = new Uri(info.RepositoryUrl);
                if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    info.Host = "git@" + uri.Host;
                    info.RepositoryUrl = info.Host + ":" + uri.AbsolutePath.TrimStart('/');
                    info.UseSSH = true;
                }
            }

            return info;
        }
Ejemplo n.º 6
0
 public virtual bool TryGetRepositoryInfo(HttpRequest request, JObject payload, out RepositoryInfo repositoryInfo)
 {
     repositoryInfo = GetRepositoryInfo(request, payload);
     return repositoryInfo != null && repositoryInfo.IsValid();
 }
Ejemplo n.º 7
0
 public virtual void Fetch(RepositoryInfo repositoryInfo, string targetBranch)
 {
     // Fetch from url
     _gitServer.FetchWithoutConflict(repositoryInfo.RepositoryUrl, "external", targetBranch);
 }
Ejemplo n.º 8
0
        private void PerformDeployment(RepositoryInfo repositoryInfo, string targetBranch)
        {
            bool hasPendingDeployment;

            do
            {
                hasPendingDeployment = false;

                using (_tracer.Step("Performing fetch based deployment"))
                {
                    using (_deploymentManager.CreateTemporaryDeployment(Resources.FetchingChanges))
                    {
                        // Configure the repository
                        _gitServer.Initialize(_configuration);

                        // Setup the receive info (this is important to know if branches were deleted etc)
                        _gitServer.SetReceiveInfo(repositoryInfo.OldRef, repositoryInfo.NewRef, targetBranch);

                        // Fetch from url
                        repositoryInfo.Handler.Fetch(repositoryInfo, targetBranch);

                        // Perform the actual deployment
                        _deploymentManager.Deploy(repositoryInfo.Deployer);

                        if (MarkerFileExists())
                        {
                            _tracer.Trace("Pending deployment marker file exists");

                            hasPendingDeployment = DeleteMarkerFile();

                            if (hasPendingDeployment)
                            {
                                _tracer.Trace("Deleted marker file");
                            }
                            else
                            {
                                _tracer.TraceError("Failed to delete marker file");
                            }
                        }
                    }
                }

            } while (hasPendingDeployment);
        }
Ejemplo n.º 9
0
        protected override RepositoryInfo GetRepositoryInfo(HttpRequest request, JObject payload)
        {
            var repository = payload.Value<JObject>("repository");
            var userid = payload.Value<int?>("user_id");
            var username = payload.Value<string>("user_name");

            if (repository == null || userid == null || username == null)
            {
                // doesn't look like GitlabHQ
                return null;
            }

            var info = new RepositoryInfo();

            // gitlabHq format
            // { "before":"34d62c0ad9387a8b9274ad77e878e195c342772b", "after":"02652ef69da7ee3d49134a961bffcb50702661ce", "ref":"refs/heads/master", "user_id":1, "user_name":"Remco Ros", "repository":{ "name":"inspectbin", "url":"http://gitlab.proscat.nl/inspectbin", "description":null, "homepage":"http://gitlab.proscat.nl/inspectbin"  }, "commits":[ { "id":"4109312962bb269ecc3a0d7a3c82a119dcd54c8b", "message":"add uservoice", "timestamp":"2012-11-11T14:32:02+01:00", "url":"http://gitlab.proscat.nl/inspectbin/commits/4109312962bb269ecc3a0d7a3c82a119dcd54c8b", "author":{ "name":"Remco Ros", "email":"*****@*****.**" }}], "total_commits_count":12 }
            info.RepositoryUrl = repository.Value<string>("url");

            // Currently Gitlab url's are broken.
            if (!info.RepositoryUrl.EndsWith(".git"))
            {
                info.RepositoryUrl += ".git";
            }

            // work around missing 'private' property, if missing assume is private.
            JToken priv;
            if (repository.TryGetValue("private", out priv))
            {
                info.IsPrivate = priv.ToObject<bool>();
            }
            else
            {
                info.IsPrivate = true;
            }

            // The format of ref is refs/something/something else
            // For master it's normally refs/head/master
            string @ref = payload.Value<string>("ref");

            if (String.IsNullOrEmpty(@ref))
            {
                return null;
            }
            info.OldRef = payload.Value<string>("before");
            info.NewRef = payload.Value<string>("after");

            info.Deployer = "GitlabHQ";

            // private repo, use SSH
            if (info.IsPrivate)
            {
                Uri uri = new Uri(info.RepositoryUrl);
                if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    info.Host = "git@" + uri.Host;
                    info.RepositoryUrl = info.Host + ":" + uri.AbsolutePath.TrimStart('/');
                    info.UseSSH = true;
                }
            }

            return info;
        }