From 02c56940be7578c9c94e8144407af0a17617f562 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Mon, 10 May 2021 15:02:06 -0300 Subject: [PATCH] Populate RepositoryBranch automatically Support most popular CI systems. Fixes #57 --- .../NuGetizer.PackageMetadata.targets | 28 +++++++++++++++++++ src/NuGetizer.Tests/given_sourcelink.cs | 7 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/NuGetizer.Tasks/NuGetizer.PackageMetadata.targets b/src/NuGetizer.Tasks/NuGetizer.PackageMetadata.targets index c6b68611..f763f170 100644 --- a/src/NuGetizer.Tasks/NuGetizer.PackageMetadata.targets +++ b/src/NuGetizer.Tasks/NuGetizer.PackageMetadata.targets @@ -21,6 +21,34 @@ Copyright (c) .NET Foundation. All rights reserved. true + + + + pr$(GITHUB_REF.Replace('refs/pull/', '').Replace('/merge', '')) + $(GITHUB_REF.Replace('refs/heads/', '').Replace('refs/tags/', '')) + + $(BUILD_SOURCEBRANCH.Replace('refs/heads/', '').Replace('refs/tags/', '')) + + pr$(APPVEYOR_PULL_REQUEST_NUMBER) + $(APPVEYOR_REPO_TAG_NAME) + $(APPVEYOR_REPO_BRANCH) + + pr$(TRAVIS_PULL_REQUEST) + $(TRAVIS_BRANCH) + + pr$(CIRCLE_PR_NUMBER) + $(CIRCLE_TAG) + $(CIRCLE_BRANCH) + + $(CI_COMMIT_TAG) + pr$(CI_MERGE_REQUEST_IID) + pr$(CI_EXTERNAL_PULL_REQUEST_IID) + $(CI_COMMIT_BRANCH) + + pr$(BUDDY_EXECUTION_PULL_REQUEST_NO) + $(BUDDY_EXECUTION_TAG) + $(BUDDY_EXECUTION_BRANCH) + diff --git a/src/NuGetizer.Tests/given_sourcelink.cs b/src/NuGetizer.Tests/given_sourcelink.cs index b0ce2707..9ebebada 100644 --- a/src/NuGetizer.Tests/given_sourcelink.cs +++ b/src/NuGetizer.Tests/given_sourcelink.cs @@ -1,4 +1,5 @@ -using Xunit; +using System; +using Xunit; using Xunit.Abstractions; namespace NuGetizer @@ -12,6 +13,9 @@ public class given_sourcelink [Fact] public void when_getting_metadata_then_adds_repository_info() { + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_REF"))) + Environment.SetEnvironmentVariable("GITHUB_REF", "refs/heads/main"); + var result = Builder.BuildProject(@" @@ -33,6 +37,7 @@ public void when_getting_metadata_then_adds_repository_info() Assert.Equal("git", metadata.GetMetadata("RepositoryType")); Assert.Equal(ThisAssembly.Project.PrivateRepositoryUrl, metadata.GetMetadata("RepositoryUrl")); Assert.NotEmpty(metadata.GetMetadata("RepositoryCommit")); + Assert.NotEmpty(metadata.GetMetadata("RepositoryBranch")); } [Fact]