Skip to content

Commit 0b1aad9

Browse files
Merge branch 'master' into issue-#96-gitrefs-implement
2 parents 7317e94 + 0bc09d2 commit 0b1aad9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+11382
-2262
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
-->
3333
- [ ] You actually ran the code that you just wrote, especially if you did just "one last quick change".
3434
- [ ] Comment-based help added/updated, including examples.
35-
- [ ] [Static analysis](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#static-analysis)
36-
is reporting back clean.
35+
- [ ] [Static analysis](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#static-analysis) is reporting back clean.
3736
- [ ] New/changed code adheres to our [coding guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#coding-guidelines).
37+
- [ ] New/changed code continues to [support the pipeline](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#pipeline-support).
3838
- [ ] Changes to the manifest file follow the [manifest guidance](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#module-manifest).
39-
- [ ] Unit tests were added/updated and are all passing. See [testing guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#testing).
39+
- [ ] Unit tests were added/updated and are all passing. See [testing guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#testing). This includes making sure that all pipeline input variations have been covered.
4040
- [ ] Relevant usage examples have been added/updated in [USAGE.md](https://github.com/microsoft/PowerShellForGitHub/blob/master/USAGE.md).
4141
- [ ] If desired, ensure your name is added to our [Contributors list](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#contributors)

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
// Run this launch config and then set breakpoints in your module.
9+
// Then you can `Import-Module -Force ./PowerShellForGitHub.psd1`
10+
// and run a function that will hit the breakpoint.
11+
"name": "PowerShell: Interactive Session",
12+
"type": "PowerShell",
13+
"request": "launch",
14+
"cwd": ""
15+
}
16+
]
17+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"editor.rulers": [
3+
100
4+
],
25
"[powershell]": {
36
"files.trimTrailingWhitespace": true
47
},

CONTRIBUTING.md

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Looking for information on how to use this module? Head on over to [README.md](
2323
* [Adding New Configuration Properties](#adding-new-configuration-properties)
2424
* [Code Comments](#code-comments)
2525
* [Debugging Tips](#debugging-tips)
26+
* [Pipeline Support](#pipeline-support)
2627
* [Testing](#testing)
2728
* [Installing Pester](#installing-pester)
2829
* [Configuring Your Environment](#configuring-your-environment)
@@ -152,7 +153,7 @@ Update-Module -Name PSScriptAnalyzer
152153
Once it's installed (or updated), from the root of your enlistment simply call
153154

154155
```powershell
155-
Invoke-ScriptAnalyzer -Path .\ -Recurse
156+
Invoke-ScriptAnalyzer -Settings ./PSScriptAnalyzerSettings.psd1 -Path ./ -Recurse
156157
```
157158

158159
That should return with no output. If you see any output when calling that command,
@@ -242,7 +243,8 @@ Here are some general guidelines
242243
reviewing/maintaining code. There are of course exceptions, but this is generally an enforced
243244
preference. The [Visual Studio Productivity Power Tools](https://visualstudiogallery.msdn.microsoft.com/34ebc6a2-2777-421d-8914-e29c1dfa7f5d)
244245
extension has a "Column Guides" feature that makes it easy to add a Guideline in column 100
245-
to make it really obvious when coding.
246+
to make it really obvious when coding. If you use VS Code, this module's `.vscode/settings.json`
247+
configures that for you automatically.
246248

247249
----------
248250

@@ -286,8 +288,71 @@ Set-GitHubConfiguration -LogRequestBody
286288

287289
----------
288290

291+
### Pipeline Support
292+
293+
This module has comprehensive support for the PowerShell pipeline. It is imperative that all
294+
new functionality added to the module embraces this design.
295+
296+
* Most functions are declared as a `filter`. This is the equivalent of a `function` where the
297+
body of the function is the `process` block, and the `begin/end` blocks are empty.
298+
299+
* In limited cases where one of the inputs is an array of something, and you specifically want that
300+
to be processed as a single command (like adding a bunch of labels to a single issue at once),
301+
you can implement it as a `function` where you use `begin/process` to gather all of the values
302+
into a single internal array, and then do the actual command execution in the `end` block. A
303+
good example of that which you can follow can be seen with `Add-GitHubIssueLabel`.
304+
305+
* Any function that requires the repo's `Uri` to be provided should be additionally aliased with
306+
`[Alias('RepositoryUrl')]` and its `[Parameter()]` definition should include `ValueFromPipelineByPropertyName`.
307+
308+
* Do not use any generic term like `Name` in your parameters. That will end up causing unintended
309+
pipeline issues down the line. For instance, if it's a label, call it `Label`, even though `Name`
310+
would make sense, other objects in the pipeline (like a `GitHub.Respository` object) also have
311+
a `name` property that would conflict.
312+
313+
* You should plan on adding additional properties to all objects being returned from an API call.
314+
Any object that is specific to a repository should have a `RepositoryUrl` `NoteProperty` added
315+
to it, enabling it to be piped-in to any other command that requires knowing which repository
316+
you're talking about. Additionally, any other property that might be necessary to uniquely
317+
identify that object in a different command should get added properties. For example, with Issues,
318+
we add both an `IssueNumber` property and an `IssueId` property to it, as the Issue commands
319+
need to interact with the `IssueNumber` while the Event commands interact with the `IssueId`.
320+
We prefer to _only_ add additional properties that are believed to be needed as input to other
321+
commands (as opposed to creating alias properties for all of the object's properties).
322+
323+
* For every major file, you will find an `Add-GitHub*AdditionalProperties` filter method at the end.
324+
If you're writing a new file, you'll need to create this yourself (and model it after an existing
325+
one). The goal of this is that you can simply pipe the output of your `Invoke-GHRestMethod`
326+
directly into this method to update the result with the additional properties, and then return
327+
that modified version to the user. The benefit of this approach is that you can then apply that
328+
filter on child objects within the primary object. For instance, a `GitHub.Issue` has multiple
329+
`GitHub.User` objects, `GitHub.Label` objects, a `GitHub.Milestone` object and more. Within
330+
`Add-GitHubIssueAdditionalProperties`, it just needs to know to call the appropriate
331+
`Add-GitHub*AdditionalProperties` method on the qualifying child properties, without needing to
332+
know anything more about them.
333+
334+
* That method will also "type" information to each object. This is forward-looking work to ease
335+
support for providing formatting of various object types in the future. That type should be
336+
defined at the top of the current file at the script level (see other files for an example),
337+
and you should be sure to both specify it in the `.OUTPUTS` section of the Comment Based Help (CBH)
338+
for the command, as well as with `[OutputType({$script:GitHubUserTypeName})]` (for example).
339+
340+
* Going along with the `.OUTPUTS` is the `.INPUTS` section. Please maintain this section as well.
341+
If you add any new type that will gain a `RepositoryUrl` property, then you'll need to update
342+
virtually _all_ of the `.INPUTS` entries across all of the files where the function has a `Uri`
343+
parameter. Please keep these type names alphabetical.
344+
345+
* To enable debugging issues involving pipeline support, there is an additional configuration
346+
property that you might use: `Set-GitHubConfiguration -DisablePipelineSupport`. That will
347+
prevent the module from adding _any_ additional properties to the objects.
348+
349+
----------
350+
289351
### Testing
290352
[![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
353+
[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
354+
[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
355+
291356

292357
#### Installing Pester
293358
This module supports testing using the [Pester UT framework](https://github.com/pester/Pester).
@@ -350,6 +415,8 @@ There are many more nuances to code-coverage, see
350415

351416
#### Automated Tests
352417
[![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
418+
[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
419+
[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/ms/PowerShellForGitHub/109/master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
353420

354421
These test are configured to automatically execute upon any update to the `master` branch
355422
of `microsoft/PowerShellForGitHub`.
@@ -362,9 +429,9 @@ as well...it is stored, encrypted, within Azure DevOps. It is not accessible fo
362429
the CI pipeline. To run the tests locally with your own account, see
363430
[configuring-your-environment](#configuring-your-environment).
364431

365-
> NOTE: We're currently encountering issues with the tests successfully running within the pipeline.
366-
> They do complete successfully locally, so please test your changes locally before submitting a
367-
> pull request.
432+
> Your change must successfully pass all tests before they will be merged. While we will run a CI
433+
> build on your behalf for any submitted pull request, it's to your benefit to verify your changes
434+
> locally first.
368435
369436
#### New Test Guidelines
370437
Your tests should have NO dependencies on an account being set up in a specific way. They should
@@ -486,6 +553,7 @@ Thank you to all of our contributors, no matter how big or small the contributio
486553
- **[Shannon Deminick (@Shazwazza)](http://github.com/Shazwazza)**
487554
- **[Jess Pomfret (@jpomfret)](https://github.com/jpomfret)**
488555
- **[Giuseppe Campanelli (@themilanfan)](https://github.com/themilanfan)**
556+
- **[Christoph Bergmeister (@bergmeister)](https://github.com/bergmeister)**
489557

490558
----------
491559

GitHubAnalytics.ps1

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ function Group-GitHubIssue
2424
The date property that should be inspected when determining which week grouping the issue
2525
if part of.
2626
27+
.INPUTS
28+
GitHub.Issue
29+
2730
.OUTPUTS
28-
[PSCustomObject[]] Collection of issues and counts, by week, along with the total count of issues.
31+
[PSCustomObject[]]
32+
Collection of issues and counts, by week, along with the total count of issues.
2933
3034
.EXAMPLE
3135
$issues = @()
@@ -90,8 +94,12 @@ function Group-GitHubIssue
9094
foreach ($week in $weekDates)
9195
{
9296
$filteredIssues = @($Issue | Where-Object {
93-
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
94-
(($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek))
97+
(($DateType -eq 'Created') -and
98+
($_.created_at -ge $week) -and
99+
($_.created_at -le $endOfWeek)) -or
100+
(($DateType -eq 'Closed') -and
101+
($_.closed_at -ge $week) -and
102+
($_.closed_at -le $endOfWeek))
95103
})
96104

97105
$endOfWeek = $week
@@ -144,6 +152,9 @@ function Group-GitHubPullRequest
144152
The date property that should be inspected when determining which week grouping the
145153
pull request if part of.
146154
155+
.INPUTS
156+
GitHub.PullRequest
157+
147158
.OUTPUTS
148159
[PSCustomObject[]] Collection of pull requests and counts, by week, along with the
149160
total count of pull requests.
@@ -211,8 +222,12 @@ function Group-GitHubPullRequest
211222
foreach ($week in $weekDates)
212223
{
213224
$filteredPullRequests = @($PullRequest | Where-Object {
214-
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
215-
(($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek))
225+
(($DateType -eq 'Created') -and
226+
($_.created_at -ge $week) -and
227+
($_.created_at -le $endOfWeek)) -or
228+
(($DateType -eq 'Merged') -and
229+
($_.merged_at -ge $week) -and
230+
($_.merged_at -le $endOfWeek))
216231
})
217232

218233
$endOfWeek = $week
@@ -265,6 +280,7 @@ function Get-WeekDate
265280
Get-WeekDate -Weeks 10
266281
#>
267282
[CmdletBinding()]
283+
[OutputType([DateTime[]])]
268284
param(
269285
[ValidateRange(0, 10000)]
270286
[int] $Weeks = 12

0 commit comments

Comments
 (0)