Beispiel #1
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            var sessionToken = payload.Value<JObject>("sessionToken");

            var info = new GitDeploymentInfo { RepositoryType = RepositoryType.Git };
            info.Deployer = GetDeployer();

            // even it is empty password we need to explicitly say so (with colon).
            // without colon, LibGit2Sharp is not working
            Uri remoteUrl = new Uri(_settings.GetValue("RepoUrl"));
            if (sessionToken == null)
            {
                // if there is no session token, fallback to use raw remoteUrl from setting.xml
                info.RepositoryUrl = remoteUrl.AbsoluteUri;
            }
            else
            {
                info.RepositoryUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}:@{2}{3}",
                    remoteUrl.Scheme,
                    sessionToken.Value<string>("token"),
                    remoteUrl.Authority,
                    remoteUrl.PathAndQuery);
            }

            info.TargetChangeset = DeploymentManager.CreateTemporaryChangeSet(
                authorName: info.Deployer,
                authorEmail: info.Deployer,
                message: String.Format(CultureInfo.CurrentUICulture, Resources.Vso_Synchronizing)
            );

            return info;
        }
Beispiel #2
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            var sessionToken = payload.Value <JObject>("sessionToken");

            var info = new GitDeploymentInfo {
                RepositoryType = RepositoryType.Git
            };

            info.Deployer = GetDeployer();

            // even it is empty password we need to explicitly say so (with colon).
            // without colon, LibGit2Sharp is not working
            Uri remoteUrl = new Uri(_settings.GetValue("repoUrl"));

            info.RepositoryUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}:@{2}{3}",
                                               remoteUrl.Scheme,
                                               sessionToken.Value <string>("token"),
                                               remoteUrl.Authority,
                                               remoteUrl.PathAndQuery);

            info.TargetChangeset = DeploymentManager.CreateTemporaryChangeSet(
                authorName: info.Deployer,
                authorEmail: info.Deployer,
                message: String.Format(CultureInfo.CurrentUICulture, Resources.Vso_Synchronizing)
                );

            return(info);
        }
Beispiel #3
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            JObject repository = payload.Value <JObject>("repository");

            if (repository == null)
            {
                return(null);
            }

            // The format of ref is refs/something/something else
            // e.g. refs/head/master or refs/head/foo/bar
            string branch = payload.Value <string>("ref");

            if (String.IsNullOrEmpty(branch) || !branch.StartsWith("refs/", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            else
            {
                // Extract the name from refs/head/master notation.
                int secondSlashIndex = branch.IndexOf('/', 5);
                branch = branch.Substring(secondSlashIndex + 1);
                if (!branch.Equals(targetBranch, StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }
            }

            var info = new GitDeploymentInfo {
                RepositoryType = RepositoryType.Git
            };

            // github format
            // { repository: { url: "https//...", private: False }, ref: "", before: "", after: "" }
            info.RepositoryUrl = repository.Value <string>("url");
            info.Deployer      = GetDeployer(request);
            info.NewRef        = payload.Value <string>("after");
            var commits = payload.Value <JArray>("commits");

            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            // private repo, use SSH
            bool isPrivate = repository.Value <bool>("private");

            if (isPrivate)
            {
                Uri uri = new Uri(info.RepositoryUrl);
                if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    var host = "git@" + uri.Host;
                    info.RepositoryUrl = host + ":" + uri.AbsolutePath.TrimStart('/');
                }
            }

            return(info);
        }
Beispiel #4
0
 public override DeployAction TryParseDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch, out DeploymentInfo deploymentInfo)
 {
     deploymentInfo = null;
     if (request.Headers["X-Github-Event"] != null)
     {
         GitDeploymentInfo gitDeploymentInfo = GetDeploymentInfo(request, payload, targetBranch);
         deploymentInfo = gitDeploymentInfo;
         return(deploymentInfo == null || IsDeleteCommit(gitDeploymentInfo.NewRef) ? DeployAction.NoOp : DeployAction.ProcessDeployment);
     }
     return(DeployAction.UnknownPayload);
 }
Beispiel #5
0
        public override DeployAction TryParseDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch, out DeploymentInfo deploymentInfo)
        {
            GitDeploymentInfo gitDeploymentInfo = GetDeploymentInfo(request, payload, targetBranch);

            if (gitDeploymentInfo != null && gitDeploymentInfo.IsValid())
            {
                deploymentInfo = gitDeploymentInfo;
                return(IsDeleteCommit(gitDeploymentInfo.NewRef) ? DeployAction.NoOp : DeployAction.ProcessDeployment);
            }
            deploymentInfo = null;
            return(DeployAction.UnknownPayload);
        }
Beispiel #6
0
        public override DeployAction TryParseDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch, out DeploymentInfo deploymentInfo)
        {
            deploymentInfo = null;
            if (request.UserAgent != null &&
                request.UserAgent.StartsWith("Codebasehq", StringComparison.OrdinalIgnoreCase))
            {
                GitDeploymentInfo gitDeploymentInfo = GetDeploymentInfo(request, payload, targetBranch);
                deploymentInfo = gitDeploymentInfo;
                return(deploymentInfo == null || IsDeleteCommit(gitDeploymentInfo.NewRef) ? DeployAction.NoOp : DeployAction.ProcessDeployment);
            }

            return(DeployAction.UnknownPayload);
        }
Beispiel #7
0
        protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            var repository = payload.Value <JObject>("repository");

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

            var userid   = payload.Value <int?>("user_id");
            var username = payload.Value <string>("user_name");
            var url      = repository.Value <string>("url");

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

            // 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);
            }

            string newRef = payload.Value <string>("after");

            if (IsDeleteCommit(newRef))
            {
                return(null);
            }

            var commits = payload.Value <JArray>("commits");
            var info    = new GitDeploymentInfo {
                RepositoryType = RepositoryType.Git
            };

            info.NewRef          = payload.Value <string>("after");
            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            var isPrivate = repository.Value <int>("visibility_level") != PublicVisibilityLevel;

            info.RepositoryUrl = isPrivate ? repository.Value <string>("git_ssh_url") : repository.Value <string>("git_http_url");
            info.Deployer      = "GitlabHQ";

            return(info);
        }
Beispiel #8
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            JObject repository = payload.Value<JObject>("repository");
            if (repository == null)
            {
                return null;
            }

            // The format of ref is refs/something/something else
            // e.g. refs/head/master or refs/head/foo/bar
            string branch = payload.Value<string>("ref");

            if (String.IsNullOrEmpty(branch) || !branch.StartsWith("refs/", StringComparison.OrdinalIgnoreCase))
            {
                return null;
            }
            else
            {
                // Extract the name from refs/head/master notation.
                int secondSlashIndex = branch.IndexOf('/', 5);
                branch = branch.Substring(secondSlashIndex + 1);
                if (!branch.Equals(targetBranch, StringComparison.OrdinalIgnoreCase))
                {
                    return null;
                }
            }

            var info = new GitDeploymentInfo { RepositoryType = RepositoryType.Git };
            // github format
            // { repository: { url: "https//...", private: False }, ref: "", before: "", after: "" } 
            info.RepositoryUrl = repository.Value<string>("url");
            info.Deployer = GetDeployer(request);
            info.NewRef = payload.Value<string>("after");
            var commits = payload.Value<JArray>("commits");

            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            // private repo, use SSH
            bool isPrivate = repository.Value<bool>("private");
            if (isPrivate)
            {
                Uri uri = new Uri(info.RepositoryUrl);
                if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    var host = "git@" + uri.Host;
                    info.RepositoryUrl = host + ":" + uri.AbsolutePath.TrimStart('/');
                }
            }

            return info;            
        }
Beispiel #9
0
        public override DeployAction TryParseDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch, out DeploymentInfo deploymentInfo)
        {
            deploymentInfo = null;

            var publisherId = payload.Value <string>("publisherId");

            if (String.Equals(publisherId, "tfs", StringComparison.OrdinalIgnoreCase))
            {
                GitDeploymentInfo gitDeploymentInfo = GetDeploymentInfo(request, payload, targetBranch);
                deploymentInfo = gitDeploymentInfo;
                return(deploymentInfo == null || IsDeleteCommit(gitDeploymentInfo.NewRef) ? DeployAction.NoOp : DeployAction.ProcessDeployment);
            }

            return(DeployAction.UnknownPayload);
        }
Beispiel #10
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload)
        {
            JObject repository = payload.Value<JObject>("repository");
            if (repository == null)
            {
                return null;
            }

            var info = new GitDeploymentInfo {RepositoryType = RepositoryType.Git};
            info.RepositoryUrl = repository.Value<string>("ssh_url");
            info.Deployer = GetDeployer(request);
            info.NewRef = payload.Value<string>("after");
            var commits = payload.Value<JArray>("commits");

            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            return info;
        }
Beispiel #11
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            // the rest must exist or NullRef.
            // this allows us to identify the culprit handler
            var sessionToken = payload.Value <JObject>("sessionToken");
            var resource     = payload.Value <JObject>("resource");
            var refUpdates   = resource.Value <JArray>("refUpdates");
            var repository   = resource.Value <JObject>("repository");

            // The format of ref is refs/something/something else
            // e.g. refs/head/master or refs/head/foo/bar
            string branch = refUpdates.Last.Value <string>("name");
            // Extract the name from refs/head/master notation.
            int secondSlashIndex = branch.IndexOf('/', 5);

            branch = branch.Substring(secondSlashIndex + 1);
            if (!branch.Equals(targetBranch, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var info = new GitDeploymentInfo {
                RepositoryType = RepositoryType.Git
            };

            info.Deployer = GetDeployer(request);
            info.NewRef   = refUpdates.Last.Value <string>("newObjectId");

            // even it is empty password we need to explicitly say so (with colon).
            // without colon, LibGit2Sharp is not working
            Uri remoteUrl = new Uri(repository.Value <string>("remoteUrl"));

            info.RepositoryUrl = String.Format("{0}://{1}:@{2}{3}",
                                               remoteUrl.Scheme,
                                               sessionToken.Value <string>("token"),
                                               remoteUrl.Authority,
                                               remoteUrl.PathAndQuery);

            var commits = resource.Value <JArray>("commits");

            info.CommitId        = refUpdates.Last.Value <string>("newObjectId");
            info.TargetChangeset = ParseChangeSet(info.CommitId, commits);
            return(info);
        }
        protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            var repository = payload.Value<JObject>("repository");
            if (repository == null)
            {
                // doesn't look like GitlabHQ
                return null;
            }

            var userid = payload.Value<int?>("user_id");
            var username = payload.Value<string>("user_name");
            var url = repository.Value<string>("url");
            if (userid == null || username == null || url == null)
            {
                // doesn't look like GitlabHQ
                return null;
            }

            // 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;
            }

            string newRef = payload.Value<string>("after");
            if (IsDeleteCommit(newRef))
            {
                return null;
            }

            var commits = payload.Value<JArray>("commits");
            var info = new GitDeploymentInfo { RepositoryType = RepositoryType.Git };
            info.NewRef = payload.Value<string>("after");
            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            var isPrivate = repository.Value<int>("visibility_level") != PublicVisibilityLevel;
            info.RepositoryUrl = isPrivate ? repository.Value<string>("git_ssh_url") : repository.Value<string>("git_http_url");            
            info.Deployer = "GitlabHQ";

            return info;
        }
Beispiel #13
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            // the rest must exist or NullRef.
            // this allows us to identify the culprit handler
            var sessionToken = payload.Value <JObject>("sessionToken");
            var resource     = payload.Value <JObject>("resource");
            var refUpdates   = resource.Value <JArray>("refUpdates");
            var repository   = resource.Value <JObject>("repository");

            // The format of ref is refs/something/something else
            // e.g. refs/head/master or refs/head/foo/bar
            string branch = refUpdates.Last.Value <string>("name");
            // Extract the name from refs/head/master notation.
            int secondSlashIndex = branch.IndexOf('/', 5);

            branch = branch.Substring(secondSlashIndex + 1);
            if (!branch.Equals(targetBranch, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var info = new GitDeploymentInfo {
                RepositoryType = RepositoryType.Git
            };

            info.Deployer = GetDeployer(request);
            info.NewRef   = refUpdates.Last.Value <string>("newObjectId");

            var builder = new UriBuilder(repository.Value <string>("remoteUrl"));

            builder.UserName   = sessionToken.Value <string>("token");
            builder.Password   = String.Empty;
            info.RepositoryUrl = builder.Uri.AbsoluteUri;

            var commits = resource.Value <JArray>("commits");

            info.CommitId        = refUpdates.Last.Value <string>("newObjectId");
            info.TargetChangeset = ParseChangeSet(info.CommitId, commits);
            return(info);
        }
Beispiel #14
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            // the rest must exist or NullRef.
            // this allows us to identify the culprit handler
            var sessionToken = payload.Value<JObject>("sessionToken");
            var resource = payload.Value<JObject>("resource");
            var refUpdates = resource.Value<JArray>("refUpdates");
            var repository = resource.Value<JObject>("repository");

            // The format of ref is refs/something/something else
            // e.g. refs/head/master or refs/head/foo/bar
            string branch = refUpdates.Last.Value<string>("name");
            // Extract the name from refs/head/master notation.
            int secondSlashIndex = branch.IndexOf('/', 5);
            branch = branch.Substring(secondSlashIndex + 1);
            if (!branch.Equals(targetBranch, StringComparison.OrdinalIgnoreCase))
            {
                return null;
            }

            var info = new GitDeploymentInfo { RepositoryType = RepositoryType.Git };
            info.Deployer = GetDeployer(request);
            info.NewRef = refUpdates.Last.Value<string>("newObjectId");

            // even it is empty password we need to explicitly say so (with colon).
            // without colon, LibGit2Sharp is not working
            Uri remoteUrl = new Uri(repository.Value<string>("remoteUrl"));
            info.RepositoryUrl = String.Format("{0}://{1}:@{2}{3}",
                remoteUrl.Scheme,
                sessionToken.Value<string>("token"),
                remoteUrl.Authority,
                remoteUrl.PathAndQuery);

            var commits = resource.Value<JArray>("commits");
            info.CommitId = refUpdates.Last.Value<string>("newObjectId");
            info.TargetChangeset = ParseChangeSet(info.CommitId, commits);
            return info;            
        }
Beispiel #15
0
        protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            var sessionToken = payload.Value <JObject>("sessionToken");

            var info = new GitDeploymentInfo
            {
                RepositoryType = RepositoryType.Git,
                Deployer       = GetDeployer(),
                IsContinuous   = true
            };

            // even it is empty password we need to explicitly say so (with colon).
            // without colon, LibGit2Sharp is not working
            Uri remoteUrl = GetRemoteUrl(payload);

            if (sessionToken == null)
            {
                // if there is no session token, fallback to use raw remoteUrl from setting.xml
                info.RepositoryUrl = remoteUrl.AbsoluteUri;
            }
            else
            {
                info.RepositoryUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}:@{2}{3}",
                                                   remoteUrl.Scheme,
                                                   sessionToken.Value <string>("token"),
                                                   remoteUrl.Authority,
                                                   remoteUrl.PathAndQuery);
            }

            info.TargetChangeset = DeploymentManager.CreateTemporaryChangeSet(
                authorName: info.Deployer,
                authorEmail: info.Deployer,
                message: String.Format(CultureInfo.CurrentUICulture, Resources.Vso_Synchronizing)
                );

            return(info);
        }
Beispiel #16
0
        protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            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);
            }

            string newRef = payload.Value <string>("after");

            if (IsDeleteCommit(newRef))
            {
                return(null);
            }
            var commits = payload.Value <JArray>("commits");
            var info    = new GitDeploymentInfo {
                RepositoryType = RepositoryType.Git
            };

            info.NewRef          = payload.Value <string>("after");
            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            // 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", StringComparison.Ordinal))
            {
                info.RepositoryUrl += ".git";
            }

            // work around missing 'private' property, if missing assume is private.
            JToken priv;
            bool   isPrivate = true;

            if (repository.TryGetValue("private", out priv))
            {
                isPrivate = priv.ToObject <bool>();
            }

            // 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 = "GitlabHQ";

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

            return(info);
        }
Beispiel #17
0
        protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
        {
            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;
            }

            string newRef = payload.Value<string>("after");
            if (IsDeleteCommit(newRef))
            {
                return null;
            }
            var commits = payload.Value<JArray>("commits");
            var info = new GitDeploymentInfo { RepositoryType = RepositoryType.Git };
            info.NewRef = payload.Value<string>("after");
            info.TargetChangeset = ParseChangeSet(info.NewRef, commits);

            // 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;
            bool isPrivate = true;
            if (repository.TryGetValue("private", out priv))
            {
                isPrivate = priv.ToObject<bool>();
            }

            // 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 = "GitlabHQ";

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

            return info;
        }