public void FactoryCreatesCorrectWriter(string p_HostingService,
                                                Type p_WriterType)
        {
            var pullRequestWriterFactory = new PullRequestWriterFactory(GivenNureOptions(p_HostingService), A_USERNAME, A_PASSWORD);

            Assert.Equal(p_WriterType, pullRequestWriterFactory.Create().GetType());
        }
예제 #2
0
파일: Program.cs 프로젝트: ClaudineL/nure
        private static void Run(RuntimeParameters p_RuntimeParameters)
        {
            NureOptions nureOptions;

            try {
                TextReader json = File.OpenText(Path.Combine(p_RuntimeParameters.DirectoryPath, CONFIGURATION_FILE_NAME));
                nureOptions = JsonSerializer.CreateDefault().Deserialize <NureOptions>(new JsonTextReader(json));
                s_Logger.Info("Launching NuRe with the following configuration:\n" + nureOptions);
            } catch (FileNotFoundException exception) {
                s_Logger.Error($"Could not locate the file. {exception.Message}");
                return;
            }

            var    gitWrapper = new GitAgent(nureOptions.CommitMessage);
            string remoteName = "origin";
            string branchName;

            try {
                gitWrapper.CreateRepository(p_RuntimeParameters.DirectoryPath);
                gitWrapper.Fetch(p_RuntimeParameters, remoteName, nureOptions.HostingUrl);
                branchName = gitWrapper.SetupBranch(nureOptions.NureBranchPrefix, remoteName);
            } catch (LibGit2SharpException exception) {
                s_Logger.Error($"Could not setup the branch. {exception.Message}");
                return;
            } catch (InvalidProgramException exception) {
                s_Logger.Error($"Could not create the repository. {exception.Message}");
                return;
            } catch (UriFormatException exception) {
                s_Logger.Error($"Could not fetch the repository. Hosting Url: {nureOptions.HostingUrl}. {exception.Message}");
                return;
            }

            NuKeeperWrapper nukeeper = new NuKeeperWrapper(nureOptions, p_RuntimeParameters.DirectoryPath);

            nukeeper.Run();
            s_Logger.Info("Run Complete");

            gitWrapper.Stage();
            //todo get them from the options file
            Identity  identity  = new Identity("Jenkins", "*****@*****.**");
            Signature signature = new Signature(identity, DateTimeOffset.Now);

            try {
                gitWrapper.Commit(signature);
                gitWrapper.Push(p_RuntimeParameters);
            } catch (LibGit2SharpException exception) {
                s_Logger.Error($"Could not setup the branch. {exception.Message}");
                return;
            }

            var pullRequestWriterFactory = new PullRequestWriterFactory(nureOptions, p_RuntimeParameters.Username, p_RuntimeParameters.Password);

            pullRequestWriterFactory.Create().WritePullRequest(branchName);
        }
        public void FactoryThrowsWithInvalidHostingService()
        {
            var pullRequestWriterFactory = new PullRequestWriterFactory(GivenNureOptions("perdu"), A_USERNAME, A_PASSWORD);

            Assert.Throws <NotImplementedException>(() => pullRequestWriterFactory.Create());
        }