cake-build / cake-build/cake

[Proposal] TFBuild.PullRequest API

Open
#2,149 1 comment 1 reaction 0 assignees View on GitHub
Help wanted Improvement Up-for-grabs
Dominant language
C#
Stars
4.2k
Forks
778
Avg merge
1h 15m
Merged PRs (30d)
19

Description

I wrote a build script today that had to check `SYSTEM_PULLREQUEST_PULLREQUESTID` to see if the current build was a pull request and to form a version string.

This seems like it might be a nice way to bring the TFBuild API to parity with the AppVeyor API. I'm willing to contribute the PR! 😃

### Proposal

Source: https://docs.microsoft.com/vsts/build-release/concepts/definitions/build/variables#systempullrequestisfork

```diff
namespace Cake.Common.Build.TFBuild.Data
{
public sealed class TFBuildEnvironmentInfo : TFInfo
{
+ ///
+ /// Gets TF pull request info, or if the current build
+ /// is not for a pull request.
+ ///
+ public TFBuildPullRequestInfo PullRequest { get; }
}

+ public sealed class TFBuildPullRequestInfo : TFInfo
+ {
+ public bool IsFork => GetEnvironmentBool("SYSTEM_PULLREQUEST_ISFORK");
+
+ public int Id => GetEnvironmentInteger("SYSTEM_PULLREQUEST_PULLREQUESTID");
+
+ public int Number => GetEnvironmentInteger("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER");
+
+ public string SourceBranch => GetEnvironmentInteger("SYSTEM_PULLREQUEST_SOURCEBRANCH");
+
+ public string SourceRepositoryUri => GetEnvironmentInteger("SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI");
+
+ public string TargetBranch => GetEnvironmentInteger("SYSTEM_PULLREQUEST_TARGETBRANCH");
+ }
}
```

### Questions

1. You have `IsPullRequest` for AppVeyor. Which is preferable?
- `TFBuild.Environment.PullRequest == null`
- `TFBuild.Environment.IsPullRequest`
- `TFBuild.Environment.PullRequest.IsPullRequest`

2. To decide whether `PullRequest == null` or `IsPullRequest` should be true, we could check whether [`BUILD_REASON`](https://docs.microsoft.com/vsts/build-release/concepts/definitions/build/variables#buildreason) is `PullRequest`.
However, if possible, it might be most flexible to check for the presence or absence of `SYSTEM_PULLREQUEST_PULLREQUESTID`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.