GetProjectHooks() public method

public GetProjectHooks ( NGitLab.Models.Project project ) : IEnumerable
project NGitLab.Models.Project
return IEnumerable
Exemplo n.º 1
0
        static int DoListenerWork(ListenerOptions clo) {
            string gitServer = clo.Server;
            string gitlabauthtoken = clo.AuthToken;
            string sharedWebHookPath = clo.WebHook;
            string taskName = clo.FarmTaskName;
            string serviceUser = clo.Login;
            bool supportsSendingMessages = !string.IsNullOrEmpty(taskName);
            Stopwatch sw = Stopwatch.StartNew();

            GitLabWrapper gitLabWrapper = new GitLabWrapper(gitServer, gitlabauthtoken);
            FarmIntegrator.Start(null);

            var projects = gitLabWrapper.GetAllProjects();
            foreach (Project project in projects) {
                var hooks = gitLabWrapper.GetProjectHooks(project);
                foreach (ProjectHook hook in hooks) {
                    if (WebHookHelper.IsSameHost(hook.Url, IP) || !WebHookHelper.IsSharedHook(sharedWebHookPath, hook.Url))
                        continue;
                    Uri url = WebHookHelper.Replace(hook.Url, IP);
                    gitLabWrapper.UpdateProjectHook(project, hook, url, true, true, true);
                    Log.Message($"WebHook registered for project {project.Name} at {url}");
                }
            }

            WebServer server = new WebServer(WebHookHelper.GetSharedHookUrl(IP, sharedWebHookPath));
            server.Start();
            while (sw.Elapsed.Minutes < clo.Timeout) {
                Thread.Sleep(10);
                var request = server.GetRequest();
                if (request == null)
                    continue;
                ProcessWebHook(gitLabWrapper, serviceUser, request, supportsSendingMessages, taskName);
            }

            return 0;
        }