Skip to content

Commit f5172f5

Browse files
committed
initial commit
0 parents  commit f5172f5

31 files changed

+2003
-0
lines changed

.gitignore

+255
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# Created by https://www.gitignore.io/api/visualstudio
2+
3+
### VisualStudio ###
4+
## Ignore Visual Studio temporary files, build results, and
5+
## files generated by popular Visual Studio add-ons.
6+
7+
# User-specific files
8+
*.suo
9+
*.user
10+
*.userosscache
11+
*.sln.docstates
12+
13+
# User-specific files (MonoDevelop/Xamarin Studio)
14+
*.userprefs
15+
16+
# Build results
17+
[Dd]ebug/
18+
[Dd]ebugPublic/
19+
[Rr]elease/
20+
[Rr]eleases/
21+
x64/
22+
x86/
23+
bld/
24+
[Bb]in/
25+
[Oo]bj/
26+
[Ll]og/
27+
28+
# Visual Studio 2015 cache/options directory
29+
.vs/
30+
# Uncomment if you have tasks that create the project's static files in wwwroot
31+
#wwwroot/
32+
33+
# MSTest test Results
34+
[Tt]est[Rr]esult*/
35+
[Bb]uild[Ll]og.*
36+
37+
# NUNIT
38+
*.VisualState.xml
39+
TestResult.xml
40+
41+
# Build Results of an ATL Project
42+
[Dd]ebugPS/
43+
[Rr]eleasePS/
44+
dlldata.c
45+
46+
# DNX
47+
project.lock.json
48+
project.fragment.lock.json
49+
artifacts/
50+
51+
*_i.c
52+
*_p.c
53+
*_i.h
54+
*.ilk
55+
*.meta
56+
*.obj
57+
*.pch
58+
*.pdb
59+
*.pgc
60+
*.pgd
61+
*.rsp
62+
*.sbr
63+
*.tlb
64+
*.tli
65+
*.tlh
66+
*.tmp
67+
*.tmp_proj
68+
*.log
69+
*.vspscc
70+
*.vssscc
71+
.builds
72+
*.pidb
73+
*.svclog
74+
*.scc
75+
76+
# Chutzpah Test files
77+
_Chutzpah*
78+
79+
# Visual C++ cache files
80+
ipch/
81+
*.aps
82+
*.ncb
83+
*.opendb
84+
*.opensdf
85+
*.sdf
86+
*.cachefile
87+
*.VC.db
88+
*.VC.VC.opendb
89+
90+
# Visual Studio profiler
91+
*.psess
92+
*.vsp
93+
*.vspx
94+
*.sap
95+
96+
# TFS 2012 Local Workspace
97+
$tf/
98+
99+
# Guidance Automation Toolkit
100+
*.gpState
101+
102+
# ReSharper is a .NET coding add-in
103+
_ReSharper*/
104+
*.[Rr]e[Ss]harper
105+
*.DotSettings.user
106+
107+
# JustCode is a .NET coding add-in
108+
.JustCode
109+
110+
# TeamCity is a build add-in
111+
_TeamCity*
112+
113+
# DotCover is a Code Coverage Tool
114+
*.dotCover
115+
116+
# NCrunch
117+
_NCrunch_*
118+
.*crunch*.local.xml
119+
nCrunchTemp_*
120+
121+
# MightyMoose
122+
*.mm.*
123+
AutoTest.Net/
124+
125+
# Web workbench (sass)
126+
.sass-cache/
127+
128+
# Installshield output folder
129+
[Ee]xpress/
130+
131+
# DocProject is a documentation generator add-in
132+
DocProject/buildhelp/
133+
DocProject/Help/*.HxT
134+
DocProject/Help/*.HxC
135+
DocProject/Help/*.hhc
136+
DocProject/Help/*.hhk
137+
DocProject/Help/*.hhp
138+
DocProject/Help/Html2
139+
DocProject/Help/html
140+
141+
# Click-Once directory
142+
publish/
143+
144+
# Publish Web Output
145+
*.[Pp]ublish.xml
146+
*.azurePubxml
147+
# TODO: Comment the next line if you want to checkin your web deploy settings
148+
# but database connection strings (with potential passwords) will be unencrypted
149+
*.publishproj
150+
151+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
152+
# checkin your Azure Web App publish settings, but sensitive information contained
153+
# in these scripts will be unencrypted
154+
PublishScripts/
155+
156+
# NuGet Packages
157+
*.nupkg
158+
# The packages folder can be ignored because of Package Restore
159+
**/packages/*
160+
# except build/, which is used as an MSBuild target.
161+
!**/packages/build/
162+
# Uncomment if necessary however generally it will be regenerated when needed
163+
#!**/packages/repositories.config
164+
# NuGet v3's project.json files produces more ignoreable files
165+
*.nuget.props
166+
*.nuget.targets
167+
168+
# Microsoft Azure Build Output
169+
csx/
170+
*.build.csdef
171+
172+
# Microsoft Azure Emulator
173+
ecf/
174+
rcf/
175+
176+
# Windows Store app package directories and files
177+
AppPackages/
178+
BundleArtifacts/
179+
Package.StoreAssociation.xml
180+
_pkginfo.txt
181+
182+
# Visual Studio cache files
183+
# files ending in .cache can be ignored
184+
*.[Cc]ache
185+
# but keep track of directories ending in .cache
186+
!*.[Cc]ache/
187+
188+
# Others
189+
ClientBin/
190+
~$*
191+
*~
192+
*.dbmdl
193+
*.dbproj.schemaview
194+
*.pfx
195+
*.publishsettings
196+
node_modules/
197+
orleans.codegen.cs
198+
199+
# Since there are multiple workflows, uncomment next line to ignore bower_components
200+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
201+
#bower_components/
202+
203+
# RIA/Silverlight projects
204+
Generated_Code/
205+
206+
# Backup & report files from converting an old project file
207+
# to a newer Visual Studio version. Backup files are not needed,
208+
# because we have git ;-)
209+
_UpgradeReport_Files/
210+
Backup*/
211+
UpgradeLog*.XML
212+
UpgradeLog*.htm
213+
214+
# SQL Server files
215+
*.mdf
216+
*.ldf
217+
218+
# Business Intelligence projects
219+
*.rdl.data
220+
*.bim.layout
221+
*.bim_*.settings
222+
223+
# Microsoft Fakes
224+
FakesAssemblies/
225+
226+
# GhostDoc plugin setting file
227+
*.GhostDoc.xml
228+
229+
# Node.js Tools for Visual Studio
230+
.ntvs_analysis.dat
231+
232+
# Visual Studio 6 build log
233+
*.plg
234+
235+
# Visual Studio 6 workspace options file
236+
*.opt
237+
238+
# Visual Studio LightSwitch build output
239+
**/*.HTMLClient/GeneratedArtifacts
240+
**/*.DesktopClient/GeneratedArtifacts
241+
**/*.DesktopClient/ModelManifest.xml
242+
**/*.Server/GeneratedArtifacts
243+
**/*.Server/ModelManifest.xml
244+
_Pvt_Extensions
245+
246+
# Paket dependency manager
247+
.paket/paket.exe
248+
paket-files/
249+
250+
# FAKE - F# Make
251+
.fake/
252+
253+
# JetBrains Rider
254+
.idea/
255+
*.sln.iml

README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## TFS WebHooks
2+
3+
This project aims to work around the limitation of having build triggers listen to only one repository in TFS.
4+
5+
### What are Service hooks?
6+
7+
[The documentation will explain it better](https://www.visualstudio.com/en-us/docs/service-hooks/services/webhooks)
8+
9+
### But I don't have time to read documentation!
10+
11+
OK.
12+
In a nutshell, TFS can notify a consumer when specific events happen. Some examples of events are:
13+
14+
- A build has completed
15+
- A work item has been created
16+
- A pull request has been created
17+
18+
This allows us to trigger actions that TFS doesn't support natively when these events happen.
19+
20+
### So how is this useful?
21+
22+
In our case, TFS doesn't provide us with the capability of queing a build when a PR in any other repository than the master repository is merged.
23+
Luckily, TFS Web hooks supports, among [lots of events](https://www.visualstudio.com/docs/integrate/get-started/service-hooks/events), one when [a pull request is updated](https://www.visualstudio.com/docs/integrate/get-started/service-hooks/events#git.pullrequest.updated).
24+
25+
*I hear you screaming that an even better event exists, when [a pull request is merged](https://www.visualstudio.com/docs/integrate/get-started/service-hooks/events#git.pullrequest.merged). Unfortunately, this documentation is for VSTS, and TFS (2015 Update 2 at the time of writing) supports only a subset of these events as it's not released as frequently.*
26+
27+
Still, we can subscribe to this event and queue a build by calling back the [TFS REST API](https://www.visualstudio.com/en-us/docs/integrate/api/overview).
28+
29+
### Cool. How does this work?
30+
31+
This project relies on two projects that make the implementation very easy:
32+
33+
- [ASP.NET WebHooks](https://github.com/aspnet/WebHooks) is a library that sits on top of ASP.NET Web API and allows us to be a consumer of web hooks. It has integrated support for [VSTS and TFS web hooks](https://github.com/aspnet/WebHooks/tree/master/samples/VstsReceiver)
34+
- The [.NET Client libraries for VSTS and TFS](https://www.visualstudio.com/en-us/docs/integrate/get-started/client-libraries/dotnet). They provide a strongly-typed wrapper around the TFS REST API.
35+
36+
### Anything more I need to know?
37+
38+
We don't want to queue a build when any PR on any repository gets merged. For example, a build is usually kicked off when a pull request on the main repo is merged. Similarly, it doesn't make sense to queue a build if PRs get merged on repos that are not associated to the main repo.
39+
40+
To overcome this, we can filter the pull requests based on:
41+
42+
- The repository on which the PR has been created
43+
- The target branch of the PR
44+
- The status of the PR
45+
46+
These parameters are set in the `web.config`:
47+
48+
| Key name | Description |
49+
|----------|-------------|
50+
| PullRequestTargetBranchName | The name of the target branch of the PR |
51+
| PullRequestStatus | The status of the PR |
52+
| PullRequestRepositoryPattern | A Regex-compatible pattern for the name of the repository |
53+
54+
### What about the build we want to queue?
55+
56+
| Key name | Description |
57+
|----------|-------------|
58+
| TeamProjectCollectionUri | The URL of the target Team Project Collection |
59+
| TargetTeamProjectName | The name of the Team Project that contains the build definition |
60+
| TargetBuildDefinitionName | The name of the build definition |
61+
62+
### What about these `MS_WebHook*` keys?
63+
64+
#### `MS_WebHookReceiverSecret_VSTS`
65+
66+
This key specifies the secret for the VSTS web hooks receiver. You don't want everyone to point their subscriptions to your Web API so that's how the team behind ASP.NET WebHooks decided to implement authorization.
67+
This secret has to be appended to the URL you set up in TFS, in a query-string parameter called `code`.
68+
69+
A URL might then looks like `https://<host>/api/webhooks/incoming/vsts?code=<code>`.
70+
Let's cut this URL down to pieces:
71+
72+
- `<host>` is where your API is hosted
73+
- `/api/webhooks` is the route prefix set by ASP.NET WebHooks
74+
- `/incoming` means we are receiving a web hook (the library also allows you to be the producer of web hooks)
75+
- `/vsts` means we want to contact the VSTS-specific endpoint
76+
- `?code=<code>` to authorize VSTS or TFS to call your API
77+
78+
#### `MS_WebHookDisableHttpsCheck`
79+
80+
By default, ASP.NET WebHooks enforces that your API be available over HTTPS. This key allows to remove that requirement.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Tfs.WebHooks.IntegrationTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyProduct("Tfs.WebHooks.IntegrationTests")]
12+
[assembly: AssemblyTrademark("")]
13+
[assembly: AssemblyCulture("")]
14+
15+
// Setting ComVisible to false makes the types in this assembly not visible
16+
// to COM components. If you need to access a type in this assembly from
17+
// COM, set the ComVisible attribute to true on that type.
18+
[assembly: ComVisible(false)]
19+
20+
// The following GUID is for the ID of the typelib if this project is exposed to COM
21+
[assembly: Guid("c27a6e4e-4f86-4603-a8f1-2ad23d3a588c")]
22+
23+
// Version information for an assembly consists of the following four values:
24+
//
25+
// Major Version
26+
// Minor Version
27+
// Build Number
28+
// Revision
29+
//
30+
// You can specify all the values or you can default the Build and Revision Numbers
31+
// by using the '*' as shown below:
32+
// [assembly: AssemblyVersion("1.0.*")]
33+
[assembly: AssemblyVersion("1.0.0.0")]
34+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)