예제 #1
0
        public override void ProcessRequestBase(HttpContextBase context)
        {
            using (Tracer.Step("RpcService.ReceivePack"))
            {
                // Ensure that the target directory does not have a non-Git repository.
                IRepository repository = _repositoryFactory.GetRepository();
                if (repository != null && repository.RepositoryType != RepositoryType.Git)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    if (context.ApplicationInstance != null)
                    {
                        context.ApplicationInstance.CompleteRequest();
                    }
                    return;
                }

                bool acquired = DeploymentLock.TryLockOperation(() =>
                {
                    context.Response.ContentType = "application/x-git-receive-pack-result";

                    if (_autoSwapHandler.IsAutoSwapOngoing())
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.Conflict;
                        context.Response.Write(Resources.Error_AutoSwapDeploymentOngoing);
                        context.ApplicationInstance.CompleteRequest();
                        return;
                    }

                    string username = null;
                    if (AuthUtility.TryExtractBasicAuthUser(context.Request, out username))
                    {
                        GitServer.SetDeployer(username);
                    }

                    UpdateNoCacheForResponse(context.Response);

                    // This temporary deployment is for ui purposes only, it will always be deleted via finally.
                    ChangeSet tempChangeSet;
                    using (DeploymentManager.CreateTemporaryDeployment(Resources.ReceivingChanges, out tempChangeSet))
                    {
                        GitServer.Receive(context.Request.GetInputStream(), context.Response.OutputStream);
                    }

                    // TODO: Currently we do not support auto-swap for git push due to an issue where we already sent the headers at the
                    // beginning of the deployment and cannot flag at this point to make the auto swap (by sending the proper headers).
                    //_autoSwapHandler.HandleAutoSwap(verifyActiveDeploymentIdChanged: true);
                }, TimeSpan.Zero);

                if (!acquired)
                {
                    context.Response.StatusCode = 409;
                    context.ApplicationInstance.CompleteRequest();
                }
            }
        }
예제 #2
0
        public override void ProcessRequestBase(HttpContextBase context)
        {
            using (Tracer.Step("RpcService.ReceivePack"))
            {
                // Ensure that the target directory does not have a non-Git repository.
                IRepository repository = _repositoryFactory.GetRepository();
                if (repository != null && repository.RepositoryType != RepositoryType.Git)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    if (context.ApplicationInstance != null)
                    {
                        context.ApplicationInstance.CompleteRequest();
                    }
                    return;
                }

                try
                {
                    DeploymentLock.LockOperation(() =>
                    {
                        context.Response.ContentType = "application/x-git-receive-pack-result";

                        if (_autoSwapHandler.IsAutoSwapOngoing())
                        {
                            context.Response.StatusCode = (int)HttpStatusCode.Conflict;
                            context.Response.Write(Resources.Error_AutoSwapDeploymentOngoing);
                            context.ApplicationInstance.CompleteRequest();
                            return;
                        }

                        string username = null;
                        if (AuthUtility.TryExtractBasicAuthUser(context.Request, out username))
                        {
                            GitServer.SetDeployer(username);
                        }

                        UpdateNoCacheForResponse(context.Response);

                        // This temporary deployment is for ui purposes only, it will always be deleted via finally.
                        ChangeSet tempChangeSet;
                        using (DeploymentManager.CreateTemporaryDeployment(Resources.ReceivingChanges, out tempChangeSet))
                        {
                            GitServer.Receive(context.Request.GetInputStream(), context.Response.OutputStream);
                        }
                    }, "Handling git receive pack", TimeSpan.Zero);
                }
                catch (LockOperationException ex)
                {
                    context.Response.StatusCode = 409;
                    context.Response.Write(ex.Message);
                    context.ApplicationInstance.CompleteRequest();
                }
            }
        }
예제 #3
0
        public override void ProcessRequestBase(HttpContextBase context)
        {
            using (Tracer.Step("RpcService.UploadPackHandler"))
            {
                UpdateNoCacheForResponse(context.Response);

                context.Response.ContentType = "application/x-git-{0}-result".With("upload-pack");

                GitServer.Upload(context.Request.GetInputStream(), context.Response.OutputStream);
            }
        }
예제 #4
0
파일: KBGitTests.cs 프로젝트: upcesar/KBGit
        GitServer SpinUpServer(KBGit git, int port)
        {
            var server = new GitServer(git);

            t = new TaskFactory().StartNew(() => server.Serve(port));

            while (!server.Running.HasValue)
            {
                Thread.Sleep(50);
            }

            return(server);
        }
    public static GitServer GetServerTypeOfPath(string url)
    {
        GitServer server = GitServer.Unknow;

        if (url.IndexOf("gitlab.com") > -1)
        {
            server = GitServer.GitLab;
        }
        if (url.IndexOf("github.com") > -1)
        {
            server = GitServer.GitHub;
        }
        return(server);
    }
    public static void LoadNamespaceFromProjectGitLink(string url, out bool found, out string namespaceID, string branchName = "master")
    {
        //https://gitlab.com/eloistree/2020_06_17_VirtualRealityTags.git#9b8e47d0b2a75b8c53c1ed05f7c8048d503055f9
        found       = false;
        namespaceID = "";
        string commitName = "";
        int    sharpIndex = url.LastIndexOf("#");

        if (sharpIndex >= 0 && sharpIndex + 1 < url.Length)
        {
            commitName = url.Substring(sharpIndex + 1);
        }
        if (commitName.Length > 0)
        {
            branchName = commitName;
        }
        if (sharpIndex >= 0)
        {
            url = url.Substring(0, sharpIndex);
        }

        url = url.ToLower();

        GitServer server = GetServerTypeOfPath(url);

        url = url.Replace(".git", "");
        int startIndex = url.IndexOf(".com/");

        if (startIndex < 0)
        {
            return;
        }
        url = url.Substring(startIndex + 5);

        // Debug.Log("url:" + url);
        string[] tokens = url.Split('/');
        if (tokens.Length < 2)
        {
            return;
        }
        string user = tokens[0], project = tokens[1];

        // Debug.Log("keys:" + server + " "+ user + " " + project + " " +branchName);
        LoadNamespaceFromUrl(server, user, project, branchName, out found, out namespaceID);

//        Debug.Log("NP:" + namespaceID);

        //https://gitlab.com/eloistree/2020_05_25_KoFiCount.git
        //https://github.com/EloiStree/2019_07_21_QuickGitUtility
    }
    public static void LoadNamespaceFromUrl(GitServer server, string userName, string projectName, string projectBranch, out bool found, out string namespaceID)
    {
        string url = "";

        if (server == GitServer.GitLab)
        {
            url = string.Format("https://gitlab.com/{0}/{1}/-/raw/{2}/package.json", userName, projectName, projectBranch);
        }
        else if (server == GitServer.GitHub)
        {
            url = string.Format("https://raw.githubusercontent.com/{0}/{1}/{2}/package.json"
                                , userName, projectName, projectBranch);
        }
        // Debug.Log("Url to to search:" + url);
        LoadNamespaceFromUrl(url, out found, out namespaceID);
    }
    public static void PushLocalToNewOnline(GitServer server, string directoryPath, string userName, string newRepoName, out string gitCreatedUrl)
    {
        gitCreatedUrl = "";
        switch (server)
        {
        //case GitServer.GitHub:
        //    PushLocalToGitHub(directoryPath, userName, newRepoName, out gitCreatedUrl);
        //    break;
        case GitServer.GitLab:
            PushLocalToGitLab(directoryPath, userName, newRepoName, out gitCreatedUrl);
            break;

        case GitServer.GitHub:
            PushLocalToGitHub(directoryPath, userName, newRepoName, out gitCreatedUrl);
            break;

        default:
            break;
        }
    }
예제 #9
0
 /// <summary>
 /// Creates default config with given params
 /// </summary>
 /// <param name="_Name"></param>
 /// <param name="_ServerPath"></param>
 /// <param name="_ModType"></param>
 /// <param name="_IsEnabled"></param>
 /// <param name="_GitBranch"></param>
 /// <param name="_GitUrl"></param>
 /// <param name="_GitToken"></param>
 /// <param name="_GitServer"></param>
 /// <param name="_MissionDifficulty"></param>
 /// <param name="_RandomizeFunctions"></param>
 /// <param name="_RandomizeGlobalVariables"></param>
 /// <param name="_RandomizeLocalVariables"></param>
 /// <param name="_SingleLineFunction"></param>
 /// <returns>new PboFile()</returns>
 public PBOFile Values(string _Name = "NewAddon", string _ServerPath = "c:\\Arma3\\@Server", PboModType _ModType = PboModType.ServerMod, bool _IsEnabled = true, string _GitBranch = "repo-main", string _GitUrl = "https://github.com/user/repo/archive/master.zip", string _GitToken = "xxxxx", GitServer _GitServer = GitServer.GitHub, MissionDifficulty _MissionDifficulty = MissionDifficulty.recruit,bool _RandomizeFunctions = false, bool _RandomizeGlobalVariables = false, bool _RandomizeLocalVariables = false, bool _SingleLineFunction = false) => new PBOFile() {
     ModType = _ModType,
     IsEnabled = _IsEnabled, 
     Name = _Name,
     GitBranch = _GitBranch,
     GitUrl = _GitUrl,
     GitToken = _GitToken,
     GitServer = _GitServer,
     ServerPath = _ServerPath,
     MissionDifficulty = _MissionDifficulty,
     RandomizeFunctions = _RandomizeFunctions,
     RandomizeGlobalVariables = _RandomizeGlobalVariables,
     RandomizeLocalVariables = _RandomizeLocalVariables,
     SingleLineFunctions = _SingleLineFunction
 };
예제 #10
0
파일: Program.cs 프로젝트: chivery/GitHub
 static void Main(string[] args)
 {
     Console.WriteLine( GitServer.Hello().ToHeader());
     Console.ReadLine();
 }