/// <summary> /// Initializes a new instance of the GitHubWebhookMSBuildExecuter class. /// </summary> /// <param name="projectFile">The path to the MSBuild project file to execute.</param> /// <param name="hook">The <see cref="GitHubWebhook"/> to inject properties and items from.</param> public GitHubWebhookMSBuildExecuter(string projectFile, GitHubWebhook hook) { if (String.IsNullOrEmpty(projectFile)) { throw new ArgumentNullException("projectFile", "projectFile must contain a value."); } projectFile = projectFile.RootPath(); if (!File.Exists(projectFile)) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, @"The path ""{0}"" does not exist.", projectFile), "projectFile"); } if (hook == null) { throw new ArgumentNullException("hook", "hook cannot be null."); } this.Hook = hook; this.ProjectFile = projectFile; }
/// <summary> /// Prepares the given MSBuild <see cref="Project"/> with properties and items from the given <see cref="GitHubWebhook"/>. /// </summary> /// <param name="project">The project to prepare.</param> /// <param name="hook">The webhook to prepare the project with.</param> public static void PrepareProject(Project project, GitHubWebhook hook) { BuildPropertyGroup properties = project.AddNewPropertyGroup(false); properties.AddNewProperty("GitHubAfter", hook.After); properties.AddNewProperty("GitHubBefore", hook.Before); properties.AddNewProperty("GitHubRef", hook.Ref); properties.AddNewProperty("GitHubRepositoryDescription", hook.Repository.Description); properties.AddNewProperty("GitHubRepositoryForks", hook.Repository.Forks.ToString(CultureInfo.InvariantCulture)); properties.AddNewProperty("GitHubRepositoryHomepage", hook.Repository.Homepage); properties.AddNewProperty("GitHubRepositoryName", hook.Repository.Name); properties.AddNewProperty("GitHubRepositoryOwnerName", hook.Repository.Owner.Name); properties.AddNewProperty("GitHubRepositoryOwnerEmail", hook.Repository.Owner.Email); properties.AddNewProperty("GitHubRepositoryPlegie", hook.Repository.Plegie); properties.AddNewProperty("GitHubRepositoryPrivate", hook.Repository.Private.ToString(CultureInfo.InvariantCulture)); properties.AddNewProperty("GitHubRepositoryUrl", hook.Repository.Url); properties.AddNewProperty("GitHubRepositoryWatchers", hook.Repository.Watchers.ToString(CultureInfo.InvariantCulture)); BuildItemGroup commits = project.AddNewItemGroup(); foreach (GitHubWebhookCommit commit in hook.Commits) { BuildItem item = commits.AddNewItem("GitHubCommit", commit.Url); item.SetMetadata("Id", commit.Id); item.SetMetadata("Message", commit.Message); item.SetMetadata("Timestamp", commit.Timestamp); item.SetMetadata("AuthorName", commit.Author.Name); item.SetMetadata("AuthorEmail", commit.Author.Email); } }