├── images
├── vsts_pat.png
├── authz_aci_1.png
├── authz_aci_2.png
├── authz_aci_3.png
├── authz_aci_4.png
├── review_bot.png
├── service_bus.png
├── share_upload_1.png
├── share_upload_2.png
├── share_upload_3.png
├── share_upload_4.png
├── vsts-pr-reviewer.png
├── vsts_service_hook_1.png
└── vsts_service_hook_2.png
├── CHANGELOG.md
├── .github
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── LICENSE.md
├── CONTRIBUTING.md
├── .gitignore
├── README.md
└── azuredeploy.json
/images/vsts_pat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/vsts_pat.png
--------------------------------------------------------------------------------
/images/authz_aci_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/authz_aci_1.png
--------------------------------------------------------------------------------
/images/authz_aci_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/authz_aci_2.png
--------------------------------------------------------------------------------
/images/authz_aci_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/authz_aci_3.png
--------------------------------------------------------------------------------
/images/authz_aci_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/authz_aci_4.png
--------------------------------------------------------------------------------
/images/review_bot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/review_bot.png
--------------------------------------------------------------------------------
/images/service_bus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/service_bus.png
--------------------------------------------------------------------------------
/images/share_upload_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/share_upload_1.png
--------------------------------------------------------------------------------
/images/share_upload_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/share_upload_2.png
--------------------------------------------------------------------------------
/images/share_upload_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/share_upload_3.png
--------------------------------------------------------------------------------
/images/share_upload_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/share_upload_4.png
--------------------------------------------------------------------------------
/images/vsts-pr-reviewer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/vsts-pr-reviewer.png
--------------------------------------------------------------------------------
/images/vsts_service_hook_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/vsts_service_hook_1.png
--------------------------------------------------------------------------------
/images/vsts_service_hook_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-vsts-pr-reviewer-logicapps-servicebus/master/images/vsts_service_hook_2.png
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [project-title] Changelog
2 |
3 |
4 | # x.y.z (yyyy-mm-dd)
5 |
6 | *Features*
7 | * ...
8 |
9 | *Bug Fixes*
10 | * ...
11 |
12 | *Breaking Changes*
13 | * ...
14 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to [project-title]
2 |
3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5 | the rights to use your contribution. For details, visit https://cla.microsoft.com.
6 |
7 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
8 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
9 | provided by the bot. You will only need to do this once across all repos using our CLA.
10 |
11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14 |
15 | - [Code of Conduct](#coc)
16 | - [Issues and Bugs](#issue)
17 | - [Feature Requests](#feature)
18 | - [Submission Guidelines](#submit)
19 |
20 | ## Code of Conduct
21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22 |
23 | ## Found an Issue?
24 | If you find a bug in the source code or a mistake in the documentation, you can help us by
25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26 | [submit a Pull Request](#submit-pr) with a fix.
27 |
28 | ## Want a Feature?
29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30 | Repository. If you would like to *implement* a new feature, please submit an issue with
31 | a proposal for your work first, to be sure that we can use it.
32 |
33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34 |
35 | ## Submission Guidelines
36 |
37 | ### Submitting an Issue
38 | Before you submit an issue, search the archive, maybe your question was already answered.
39 |
40 | If your issue appears to be a bug, and hasn't been reported, open a new issue.
41 | Help us to maximize the effort we can spend fixing issues and adding new
42 | features, by not reporting duplicate issues. Providing the following information will increase the
43 | chances of your issue being dealt with quickly:
44 |
45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46 | * **Version** - what version is affected (e.g. 0.1.2)
47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48 | * **Browsers and Operating System** - is this a problem with all browsers?
49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps
50 | * **Related Issues** - has a similar issue been reported before?
51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52 | causing the problem (line of code or commit)
53 |
54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55 |
56 | ### Submitting a Pull Request (PR)
57 | Before you submit your Pull Request (PR) consider the following guidelines:
58 |
59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR
60 | that relates to your submission. You don't want to duplicate effort.
61 |
62 | * Make your changes in a new git fork:
63 |
64 | * Commit your changes using a descriptive commit message
65 | * Push your fork to GitHub:
66 | * In GitHub, create a pull request
67 | * If we suggest changes then:
68 | * Make the required updates.
69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70 |
71 | ```shell
72 | git rebase master -i
73 | git push -f
74 | ```
75 |
76 | That's it! Thank you for your contribution!
77 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # .NET Core
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 | **/Properties/launchSettings.json
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 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 |
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 |
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 |
129 | # Web workbench (sass)
130 | .sass-cache/
131 |
132 | # Installshield output folder
133 | [Ee]xpress/
134 |
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 |
145 | # Click-Once directory
146 | publish/
147 |
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 |
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 |
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 |
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 |
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 |
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 |
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 |
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 |
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 |
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 |
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 |
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 |
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 |
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 |
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 |
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 |
239 | # Typescript v1 declaration files
240 | typings/
241 |
242 | # Visual Studio 6 build log
243 | *.plg
244 |
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 |
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 |
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 |
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 |
263 | # FAKE - F# Make
264 | .fake/
265 |
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 |
270 | # CodeRush
271 | .cr/
272 |
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 |
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 |
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 |
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - javascript
5 | products:
6 | - azure
7 | - azure-devops
8 | - azure-service-bus
9 | - azure-logic-apps
10 | description: "An Azure Pipelines pull request review service, built on Azure Container Instance, Azure Logic App and Azure Service Bus."
11 | urlFragment: aci-azure-pipelines-pr-reviewer-logicapps-servicebus
12 | ---
13 |
14 | # Azure Pipelines PR Reviewer
15 |
16 | An Azure Pipelines pull request review service, built on Azure Container Instance, Azure Logic App and Azure Service Bus.
17 |
18 | 
19 |
20 | ## How it works
21 |
22 | When a Azure Pipelines pull request is created or updated, Azure Pipelines sends a notification to an Azure Service Bus topic. As a subscriber of the topic, an Azure Logic App starts an Azure Container Instance upon getting the notification. The container in Azure Container Instance utilizes Azure Pipelines REST API to check the changes in the pull request, leave comments and vote approve/wait.
23 |
24 | 
25 |
26 | ## How to deploy
27 |
28 | ### Deploy ARM template
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | The ARM template deployment deploys Logic App, Service Bus Namepsace and Topic, it also registers Logic App as a subscriber of the Service Bus Topic. Logic App is configured to start a Container Instance with docker image [wenwu/pr-review](https://hub.docker.com/r/wenwu449/pr-review/) when getting a message from the Service Bus topic.
38 |
39 | ### Authorize ACI connection in Logic App
40 | To grant Logic App the permission to create Container Instance, we need to authorize ACI connection in Logic App.
41 |
42 | After deployment, navigate to the resource group in Azure portal, open the logic app resource:
43 |
44 | 
45 |
46 | Open designer (click "Edit" button), click "Connections" in the flow:
47 |
48 | 
49 |
50 | Click "Invalid connection" to configure connection:
51 |
52 | 
53 |
54 | Sign in with user account or service pricipal.
55 |
56 | 
57 |
58 | Click "Save" button to save the changes.
59 |
60 | ### Configure Azure Pipelines
61 |
62 | #### Configure Service Hook
63 |
64 | [Service hooks](https://docs.microsoft.com/en-us/vsts/service-hooks/overview?view=vsts) enable you to perform tasks on other services when events happen in your Azure Pipelines projects. We will configure service hook so that message will be sent to Serivce Bus Topic when pull request is created.
65 |
66 | 1. Get service bus topic connection string with commands, `` is the name of resource group used for ARM template deployment:
67 | ```
68 | groupName=
69 | nsName=$(az servicebus namespace list -g $groupName | jq -r ".[0].name")
70 | az servicebus topic authorization-rule keys list -g $groupName --namespace-name $nsName --topic-name vsts-pr-update -n vsts-hook | jq -r ".primaryConnectionString" | rev | cut -d ';' -f2- | rev
71 | ```
72 | Copy the connection string. You will need to provide this value when creating a Service Hook subscription.
73 |
74 | 2. Go to Azure Pipelines project to configure service hook.
75 |
76 | Click "Create subscription"
77 |
78 | 
79 |
80 | Select "Azure Service Bus" and click "Next".
81 |
82 | Select "Pull Request created" trigger, configure "Repository", "Target branch" and other filters if applies, click "Next".
83 |
84 | 
85 |
86 | Select "Send a message to a Service Bus Topic" at "Perform this action", input the connection string got in step 1 at "SAS connection string", input "vsts-pr-update" at "Topic name", click "Test" to test, then click "Finsh".
87 |
88 | 
89 |
90 | Optionally, another subscription can be created to send message when a pull request is updated.
91 |
92 | #### Get VSTS personal access token
93 |
94 | The reviewer application running in Azure Container Instance uses a Azure Pipelines [personal access token](https://docs.microsoft.com/en-us/vsts/integrate/get-started/authentication/pats?view=vsts) to read, comment and vote on a pull request.
95 |
96 | Log in Azure Pipelines, go to your security details.
97 |
98 | 
99 |
100 | Create a personal access token
101 |
102 | 
103 |
104 | Select the "Code (read and write)" scope for the token, click "Save"
105 |
106 | 
107 |
108 | When you're done, make sure to copy the token. You'll use this token in next step.
109 |
110 | **Treat the token as secret, the token is your identity and acts as you when it is used.**
111 |
112 | ### Upload VSTS config
113 |
114 | The reviewer application running in Azure Container Instance reads configuration file on an Azure Storage File Share to get the personal access token and other Azure Pipelines information.
115 |
116 | Download the [config.json](https://raw.githubusercontent.com/wenwu449/vsts-pr-review-sample/master/config.json) as a template, change the value according to your Azure Pipelines project.
117 |
118 | *userId can be get via [Accounts](https://docs.microsoft.com/en-us/rest/api/vsts/account/accounts/list) API ( `accountId` in response ) or [Get Pull Request](https://docs.microsoft.com/en-us/rest/api/vsts/git/pull%20requests/get%20pull%20request) API ( `createdBy.Id` in response )*
119 |
120 | Use Azure Portal to upload the `config.json` file to Azure Storage File Share, navigate to the resource group in Azure portal, open the storage resource (resource name may vary):
121 |
122 | 
123 |
124 | Click "Files",
125 |
126 | 
127 |
128 | Click "vsts-pr-preview", then click "config",
129 |
130 | 
131 |
132 | Click "Upload", use the file upload control to upload the `config.json` file.
133 |
134 | 
135 |
136 | Now your pull request review service is up and running!
137 |
--------------------------------------------------------------------------------
/azuredeploy.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3 | "contentVersion": "1.0.0.0",
4 | "parameters": {
5 | "location": {
6 | "defaultValue": "westus",
7 | "allowedValues": [
8 | "westus",
9 | "eastus",
10 | "westeurope",
11 | "southeastasia",
12 | "westus2"
13 | ],
14 | "type": "string"
15 | },
16 | "pr_review_image": {
17 | "defaultValue": "wenwu449/pr-review",
18 | "type": "string"
19 | }
20 | },
21 | "variables": {
22 | "logicapp_workflows_name": "vsts-pr-review",
23 | "connections_aci_name": "aci",
24 | "connections_servicebus_name": "servicebus",
25 | "servicebus_namespaces_name": "[concat('vsts-pr-', uniqueString(resourceGroup().id))]",
26 | "servicebus_topics_name": "vsts-pr-update",
27 | "servicebus_subscriptions_name": "logicapp",
28 | "authzRules_RootManageSharedAccessKey_name": "RootManageSharedAccessKey",
29 | "authzRules_vsts_hook_name": "vsts-hook",
30 | "authzRules_logic_listen_name": "logic-listen",
31 | "container_share_name": "vstspr",
32 | "container_config_path": "config",
33 | "container_log_path": "logs",
34 | "storage_account_name": "[concat('storage', uniqueString(resourceGroup().id))]",
35 | "storage_file_share": "vsts-pr-review",
36 | "storage_type": "Standard_LRS",
37 | "aci_file_share_name": "aci-file-share"
38 | },
39 | "resources": [
40 | {
41 | "type": "Microsoft.Logic/workflows",
42 | "name": "[variables('logicapp_workflows_name')]",
43 | "apiVersion": "2017-07-01",
44 | "location": "[parameters('location')]",
45 | "properties": {
46 | "state": "Enabled",
47 | "definition": {
48 | "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
49 | "contentVersion": "1.0.0.0",
50 | "parameters": {
51 | "$connections": {
52 | "defaultValue": {},
53 | "type": "Object"
54 | }
55 | },
56 | "triggers": {
57 | "vsts_pr_update_(peek-lock)": {
58 | "recurrence": {
59 | "frequency": "Minute",
60 | "interval": 3
61 | },
62 | "type": "ApiConnection",
63 | "inputs": {
64 | "host": {
65 | "connection": {
66 | "name": "@parameters('$connections')['servicebus']['connectionId']"
67 | }
68 | },
69 | "method": "get",
70 | "path": "[concat('/', variables('servicebus_topics_name'), '/subscriptions/', variables('servicebus_subscriptions_name'), '/messages/head/peek')]",
71 | "queries": {
72 | "sessionId": "None",
73 | "subscriptionType": "Main"
74 | }
75 | }
76 | }
77 | },
78 | "actions": {
79 | "Complete_the_message_in_a_topic_subscription": {
80 | "runAfter": {
81 | "Until": [
82 | "Succeeded"
83 | ]
84 | },
85 | "type": "ApiConnection",
86 | "inputs": {
87 | "host": {
88 | "connection": {
89 | "name": "@parameters('$connections')['servicebus']['connectionId']"
90 | }
91 | },
92 | "method": "delete",
93 | "path": "[concat('/', variables('servicebus_topics_name'), '/subscriptions/', variables('servicebus_subscriptions_name'), '/messages/complete')]",
94 | "queries": {
95 | "lockToken": "@triggerBody()?['LockToken']",
96 | "subscriptionType": "Main"
97 | }
98 | }
99 | },
100 | "Create_container_group": {
101 | "runAfter": {},
102 | "type": "ApiConnection",
103 | "inputs": {
104 | "body": {
105 | "location": "[parameters('location')]",
106 | "properties": {
107 | "containers": [
108 | {
109 | "name": "vstsprreview",
110 | "properties": {
111 | "command": [
112 | "/bin/sh",
113 | "-c",
114 | "[concat('./pr-review | tee -a /var/pr/', variables('container_log_path'), '/log-@{utcnow(''yyyy-MM-ddTHH-mm-ss-fffffffK'')}')]"
115 | ],
116 | "environmentVariables": [
117 | {
118 | "name": "PR_CONTENT",
119 | "value": "@triggerBody()?['ContentData']"
120 | },
121 | {
122 | "name": "VSTS_CONFIG_PATH",
123 | "value": "[concat('/var/pr/', variables('container_config_path'), '/config.json')]"
124 | }
125 | ],
126 | "image": "[parameters('pr_review_image')]",
127 | "resources": {
128 | "requests": {
129 | "cpu": 1,
130 | "memoryInGB": 1.5
131 | }
132 | },
133 | "volumeMounts": [
134 | {
135 | "mountPath": "/var/pr",
136 | "name": "[variables('container_share_name')]",
137 | "readOnly": false
138 | }
139 | ]
140 | }
141 | }
142 | ],
143 | "osType": "Linux",
144 | "restartPolicy": "OnFailure",
145 | "volumes": [
146 | {
147 | "azureFile": {
148 | "readOnly": false,
149 | "shareName": "[variables('storage_file_share')]",
150 | "storageAccountKey": "[listKeys(variables('storage_account_name'),'2017-10-01').keys[0].value]",
151 | "storageAccountName": "[variables('storage_account_name')]"
152 | },
153 | "name": "[variables('container_share_name')]"
154 | }
155 | ]
156 | },
157 | "tags": {
158 | "datetime": "@{utcNow()}"
159 | }
160 | },
161 | "host": {
162 | "connection": {
163 | "name": "@parameters('$connections')['aci']['connectionId']"
164 | }
165 | },
166 | "method": "put",
167 | "path": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(''aci-'',triggerBody()?[''LockToken''])}')]",
168 | "queries": {
169 | "x-ms-api-version": "2018-02-01-preview"
170 | }
171 | }
172 | },
173 | "Delete_container_group": {
174 | "runAfter": {
175 | "For_each": [
176 | "Succeeded"
177 | ]
178 | },
179 | "type": "ApiConnection",
180 | "inputs": {
181 | "host": {
182 | "connection": {
183 | "name": "@parameters('$connections')['aci']['connectionId']"
184 | }
185 | },
186 | "method": "delete",
187 | "path": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(body(''Create_container_group'')?[''name''])}')]",
188 | "queries": {
189 | "x-ms-api-version": "2018-02-01-preview"
190 | }
191 | }
192 | },
193 | "For_each": {
194 | "foreach": "@body('Get_properties_of_a_container_group')['properties']['containers']",
195 | "actions": {
196 | "Get_logs_of_a_container": {
197 | "runAfter": {},
198 | "type": "ApiConnection",
199 | "inputs": {
200 | "host": {
201 | "connection": {
202 | "name": "@parameters('$connections')['aci']['connectionId']"
203 | }
204 | },
205 | "method": "get",
206 | "path": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(body(''Create_container_group'')?[''name''])}/containers/@{encodeURIComponent(items(''For_each'')[''name''])}/logs')]",
207 | "queries": {
208 | "x-ms-api-version": "2018-02-01-preview"
209 | }
210 | }
211 | }
212 | },
213 | "runAfter": {
214 | "Until": [
215 | "Failed",
216 | "Succeeded"
217 | ]
218 | },
219 | "type": "Foreach"
220 | },
221 | "Until": {
222 | "actions": {
223 | "Delay_10s": {
224 | "runAfter": {
225 | "Get_properties_of_a_container_group": [
226 | "Succeeded"
227 | ]
228 | },
229 | "type": "Wait",
230 | "inputs": {
231 | "interval": {
232 | "count": 10,
233 | "unit": "Second"
234 | }
235 | }
236 | },
237 | "Get_properties_of_a_container_group": {
238 | "runAfter": {},
239 | "type": "ApiConnection",
240 | "inputs": {
241 | "host": {
242 | "connection": {
243 | "name": "@parameters('$connections')['aci']['connectionId']"
244 | }
245 | },
246 | "method": "get",
247 | "path": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(body(''Create_container_group'')?[''name''])}')]",
248 | "queries": {
249 | "x-ms-api-version": "2018-02-01-preview"
250 | }
251 | }
252 | }
253 | },
254 | "runAfter": {
255 | "Create_container_group": [
256 | "Succeeded"
257 | ]
258 | },
259 | "expression": "@equals(body('Get_properties_of_a_container_group')?['properties']?['instanceView']?['state'], 'Succeeded')",
260 | "limit": {
261 | "count": 60,
262 | "timeout": "PT5M"
263 | },
264 | "type": "Until"
265 | }
266 | },
267 | "outputs": {}
268 | },
269 | "parameters": {
270 | "$connections": {
271 | "value": {
272 | "aci": {
273 | "connectionId": "[resourceId('Microsoft.Web/connections', variables('connections_aci_name'))]",
274 | "connectionName": "aci",
275 | "id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', variables('connections_aci_name'))]"
276 | },
277 | "servicebus": {
278 | "connectionId": "[resourceId('Microsoft.Web/connections', variables('connections_servicebus_name'))]",
279 | "connectionName": "servicebus",
280 | "id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', variables('connections_servicebus_name'))]"
281 | }
282 | }
283 | }
284 | }
285 | },
286 | "dependsOn": [
287 | "[resourceId('Microsoft.Web/connections', variables('connections_aci_name'))]",
288 | "[resourceId('Microsoft.Web/connections', variables('connections_servicebus_name'))]",
289 | "[resourceId('Microsoft.ContainerInstance/containerGroups', variables('aci_file_share_name'))]",
290 | "[resourceId('Microsoft.ServiceBus/namespaces', variables('servicebus_namespaces_name'))]"
291 | ]
292 | },
293 | {
294 | "type": "Microsoft.Storage/storageAccounts",
295 | "name": "[variables('storage_account_name')]",
296 | "apiVersion": "2017-10-01",
297 | "location": "[parameters('location')]",
298 | "sku": {
299 | "name": "[variables('storage_type')]"
300 | },
301 | "kind": "Storage",
302 | "properties": {}
303 | },
304 | {
305 | "name": "[variables('aci_file_share_name')]",
306 | "type": "Microsoft.ContainerInstance/containerGroups",
307 | "apiVersion": "2018-02-01-preview",
308 | "location": "[parameters('location')]",
309 | "dependsOn": [
310 | "[concat('Microsoft.Storage/storageAccounts/', variables('storage_account_name'))]"
311 | ],
312 | "properties": {
313 | "containers": [
314 | {
315 | "name": "aci-file-share",
316 | "properties": {
317 | "image": "microsoft/azure-cli",
318 | "command": [
319 | "/bin/sh",
320 | "-c",
321 | "[concat('az storage share create -n ', variables('storage_file_share'), ' && az storage directory create -s ', variables('storage_file_share'), ' -n ', variables('container_config_path'), ' && az storage directory create -s ', variables('storage_file_share'), ' -n ', variables('container_log_path'))]"
322 | ],
323 | "environmentVariables": [
324 | {
325 | "name": "AZURE_STORAGE_KEY",
326 | "value": "[listKeys(variables('storage_account_name'),'2017-10-01').keys[0].value]"
327 | },
328 | {
329 | "name": "AZURE_STORAGE_ACCOUNT",
330 | "value": "[variables('storage_account_name')]"
331 | }
332 | ],
333 | "resources": {
334 | "requests": {
335 | "cpu": 1.0,
336 | "memoryInGb": 1.5
337 | }
338 | }
339 | }
340 | }
341 | ],
342 | "restartPolicy": "OnFailure",
343 | "osType": "Linux"
344 | }
345 | },
346 | {
347 | "type": "Microsoft.Web/connections",
348 | "name": "[variables('connections_aci_name')]",
349 | "apiVersion": "2016-06-01",
350 | "location": "[parameters('location')]",
351 | "properties": {
352 | "displayName": "[variables('connections_aci_name')]",
353 | "customParameterValues": {},
354 | "api": {
355 | "id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', variables('connections_aci_name'))]"
356 | }
357 | },
358 | "dependsOn": []
359 | },
360 | {
361 | "type": "Microsoft.Web/connections",
362 | "name": "[variables('connections_servicebus_name')]",
363 | "apiVersion": "2016-06-01",
364 | "location": "[parameters('location')]",
365 | "properties": {
366 | "displayName": "[variables('connections_servicebus_name')]",
367 | "customParameterValues": {},
368 | "api": {
369 | "id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', variables('connections_servicebus_name'))]"
370 | },
371 | "parameterValues": {
372 | "connectionString": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/topics/authorizationRules', variables('servicebus_namespaces_name'), variables('servicebus_topics_name'), variables('authzRules_logic_listen_name')),'2017-04-01').primaryConnectionString]"
373 | }
374 | }
375 | },
376 | {
377 | "type": "Microsoft.ServiceBus/namespaces",
378 | "sku": {
379 | "name": "Standard",
380 | "tier": "Standard"
381 | },
382 | "properties": {},
383 | "name": "[variables('servicebus_namespaces_name')]",
384 | "apiVersion": "2017-04-01",
385 | "location": "[parameters('location')]",
386 | "resources": [
387 | {
388 | "type": "AuthorizationRules",
389 | "name": "[variables('authzRules_RootManageSharedAccessKey_name')]",
390 | "apiVersion": "2017-04-01",
391 | "properties": {
392 | "rights": [
393 | "Listen",
394 | "Manage",
395 | "Send"
396 | ]
397 | },
398 | "dependsOn": [
399 | "[concat('Microsoft.ServiceBus/namespaces/', variables('servicebus_namespaces_name'))]"
400 | ]
401 | },
402 | {
403 | "type": "topics",
404 | "name": "[variables('servicebus_topics_name')]",
405 | "apiVersion": "2017-04-01",
406 | "properties": {
407 | "defaultMessageTimeToLive": "P14D"
408 | },
409 | "dependsOn": [
410 | "[concat('Microsoft.ServiceBus/namespaces/', variables('servicebus_namespaces_name'))]"
411 | ],
412 | "resources": [
413 | {
414 | "type": "authorizationRules",
415 | "name": "[variables('authzRules_vsts_hook_name')]",
416 | "apiVersion": "2017-04-01",
417 | "properties": {
418 | "rights": [
419 | "Send"
420 | ]
421 | },
422 | "dependsOn": [
423 | "[variables('servicebus_topics_name')]"
424 | ]
425 | },
426 | {
427 | "type": "authorizationRules",
428 | "name": "[variables('authzRules_logic_listen_name')]",
429 | "apiVersion": "2017-04-01",
430 | "properties": {
431 | "rights": [
432 | "Listen"
433 | ]
434 | },
435 | "dependsOn": [
436 | "[variables('servicebus_topics_name')]"
437 | ]
438 | },
439 | {
440 | "type": "subscriptions",
441 | "name": "[variables('servicebus_subscriptions_name')]",
442 | "apiVersion": "2017-04-01",
443 | "properties": {
444 | "lockDuration": "PT5M",
445 | "defaultMessageTimeToLive": "P14D"
446 | },
447 | "dependsOn": [
448 | "[variables('servicebus_topics_name')]"
449 | ]
450 | }
451 | ]
452 | }
453 | ]
454 | }
455 | ]
456 | }
--------------------------------------------------------------------------------