Skip to content

Adding complete Pipeline support to the entire module #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 80 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
efcc6e6
Initial thinking on pipelining
HowardWolosky Jun 4, 2020
85cfcf8
More WIP
HowardWolosky Jun 5, 2020
c8fc4d8
Completing work for GitHubUser.ps1 and GitHubRepositories.ps1
HowardWolosky Jun 5, 2020
e1d3c67
Repo fix (helps Get-GitHubRepositoryLanguage)
HowardWolosky Jun 5, 2020
0747e6c
Additional User fixes
HowardWolosky Jun 5, 2020
17cb1b1
Additional user fixes
HowardWolosky Jun 5, 2020
eefb3e3
Add Teams support
HowardWolosky Jun 5, 2020
7360b07
Add traffic support
HowardWolosky Jun 5, 2020
f41864d
Add fork support
HowardWolosky Jun 5, 2020
bce71e1
Add releases support
HowardWolosky Jun 5, 2020
c42d67c
Pull request, labels and milestone
HowardWolosky Jun 6, 2020
e8c29f2
Add Misc support
HowardWolosky Jun 6, 2020
976d57e
Add projects support
HowardWolosky Jun 6, 2020
ce3460e
Add project column support
HowardWolosky Jun 6, 2020
95c416c
Add Project Card support
HowardWolosky Jun 6, 2020
463ccc0
Add Organization and Milestone support
HowardWolosky Jun 6, 2020
396414c
Add issue support
HowardWolosky Jun 6, 2020
1076e91
Add Event support
HowardWolosky Jun 6, 2020
a6961fa
Add contents support
HowardWolosky Jun 6, 2020
5f02002
Add branches support
HowardWolosky Jun 8, 2020
a1d5936
Add Assignee support
HowardWolosky Jun 8, 2020
c9a6942
Add support for comments
HowardWolosky Jun 8, 2020
f6da52a
* [BREAKING CHANGE] Changed signature for Get-GitHubUserContextualInf…
HowardWolosky Jun 9, 2020
35ab96e
Update Traffic and Forks tests
HowardWolosky Jun 9, 2020
fef7aec
Some Pester syntax cleanup
HowardWolosky Jun 9, 2020
be76b85
Adds half of the pipeline repository tests.
HowardWolosky Jun 9, 2020
d65eb3f
Make Set-GitHubRepositoryTopic pipeline input work well with an array
HowardWolosky Jun 9, 2020
b3cc8a1
* Fixed 'GitHub' casing throughout module
HowardWolosky Jun 9, 2020
3d4fca5
Updated releases tests for pipelining
HowardWolosky Jun 9, 2020
5e9f7a3
Fixing releases and tests
HowardWolosky Jun 9, 2020
cd27d4f
Fixing some repository issues
HowardWolosky Jun 9, 2020
c5f9b3e
Migrate from PSUseDeclaredVarsMoreThanAssignments workaround to Set-S…
HowardWolosky Jun 10, 2020
0c3e884
Add pull request tests
HowardWolosky Jun 10, 2020
c1d6101
Fix Organization pipelining
HowardWolosky Jun 10, 2020
d71a5f5
Add templates for missing test files with TODO's
HowardWolosky Jun 10, 2020
7ef5043
Fix forks test names
HowardWolosky Jun 10, 2020
d3fbeab
Fixing Get-GitHubUser for specific user
HowardWolosky Jun 10, 2020
af3f0a3
Re-fixing forks tests after rebase
HowardWolosky Jun 10, 2020
a0f5746
Rename-GitHubRepository should just directly call Update-GitHubReposi…
HowardWolosky Jun 10, 2020
74ba3d6
Fix singular pull request, move tests to proper files
HowardWolosky Jun 10, 2020
2ba0e8e
Fixing repository (contributor) tests
HowardWolosky Jun 10, 2020
6344c48
Complete rewrite of milestone tests
HowardWolosky Jun 11, 2020
2644bd5
nit
HowardWolosky Jun 11, 2020
9c5a1b4
Add pipeline events tests
HowardWolosky Jun 12, 2020
3541908
Update projects tests
HowardWolosky Jun 12, 2020
c5e070b
Update project column tests
HowardWolosky Jun 12, 2020
07031e3
Update project card tests and improve project card function signatures
HowardWolosky Jun 13, 2020
237deee
The OwnerName for "Microsoft" should be lowercase
HowardWolosky Jun 13, 2020
12a088c
Breaking change: have to rename 'Name' to 'Label' for label function …
HowardWolosky Jun 13, 2020
492e396
Finishing migration of Name->Label
HowardWolosky Jun 13, 2020
d2474d0
Fixing CBH
HowardWolosky Jun 13, 2020
da4e010
Simplifying parameter sets in Get-GitHubLabel to get it working with …
HowardWolosky Jun 13, 2020
d1d47d1
Some fixes for the label UT's. still have some failures to investigate.
HowardWolosky Jun 13, 2020
e1b7a0c
All labels tests passing
HowardWolosky Jun 14, 2020
a8f0306
Completing label ut's
HowardWolosky Jun 15, 2020
cff6061
Slight update to milestone tests
HowardWolosky Jun 15, 2020
ab6e58e
Update contents tests
HowardWolosky Jun 15, 2020
f613182
Fixing repositoryName parameter
HowardWolosky Jun 15, 2020
2317730
Update branches tests
HowardWolosky Jun 15, 2020
80334d2
Updated the assignees tests
HowardWolosky Jun 15, 2020
667132a
Fixing some casing in the CBH
HowardWolosky Jun 15, 2020
ccd1b7a
Remove unnecessary TypeName parameter passing
HowardWolosky Jun 15, 2020
c09a318
Renaming GitHubComments.* -> GitHubIssueComments.*
HowardWolosky Jun 15, 2020
9305a55
Got Issue comment tests working
HowardWolosky Jun 15, 2020
0267287
Missing comment update
HowardWolosky Jun 15, 2020
d89bdb4
Fixing capitalization
HowardWolosky Jun 16, 2020
c753877
Get Issue tests passing (and fix a bug in Lock-GitHubIssue)
HowardWolosky Jun 16, 2020
48c96d9
Some minor test fixes. All passing clean
HowardWolosky Jun 16, 2020
1330394
Add tests for GitHubMiscellaneous and fix up some other tests
HowardWolosky Jun 16, 2020
6b15d1d
Update GitHubMiscellaneous tests to be compatible with Pester 5
HowardWolosky Jun 16, 2020
e62d395
Moving Contents type setting to its own function
HowardWolosky Jun 16, 2020
6d5f83d
Updating documentation
HowardWolosky Jun 16, 2020
3d3acfd
Further doc update
HowardWolosky Jun 16, 2020
1bc229c
Migrating all accept header usage to come from constants.
HowardWolosky Jun 16, 2020
6f00495
Fix milestone support in issues
HowardWolosky Jun 16, 2020
b6f3a12
Some various cleanup around removing generic 'Name' parameters, etc...
HowardWolosky Jun 17, 2020
9fe5a7b
Applying some CR feedback including limiting the lines exceeding 100 …
HowardWolosky Jun 17, 2020
13844ff
Getting the formatting of the [Parameter] property consistent across …
HowardWolosky Jun 17, 2020
34f9f3e
Updating INPUTS for all functions and adding RepositoryUrl to GitHub.…
HowardWolosky Jun 18, 2020
1095a3d
Minor update to CONTRIBUTING.md
HowardWolosky Jun 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
-->
- [ ] You actually ran the code that you just wrote, especially if you did just "one last quick change".
- [ ] Comment-based help added/updated, including examples.
- [ ] [Static analysis](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#static-analysis)
is reporting back clean.
- [ ] [Static analysis](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#static-analysis) is reporting back clean.
- [ ] New/changed code adheres to our [coding guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#coding-guidelines).
- [ ] New/changed code continues to [support the pipeline](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#pipeline-support).
- [ ] Changes to the manifest file follow the [manifest guidance](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#module-manifest).
- [ ] Unit tests were added/updated and are all passing. See [testing guidelines](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#testing).
- [ ] 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.
- [ ] Relevant usage examples have been added/updated in [USAGE.md](https://github.com/microsoft/PowerShellForGitHub/blob/master/USAGE.md).
- [ ] If desired, ensure your name is added to our [Contributors list](https://github.com/microsoft/PowerShellForGitHub/blob/master/CONTRIBUTING.md#contributors)
72 changes: 69 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Looking for information on how to use this module? Head on over to [README.md](
* [Adding New Configuration Properties](#adding-new-configuration-properties)
* [Code Comments](#code-comments)
* [Debugging Tips](#debugging-tips)
* [Pipeline Support](#pipeline-support)
* [Testing](#testing)
* [Installing Pester](#installing-pester)
* [Configuring Your Environment](#configuring-your-environment)
Expand Down Expand Up @@ -286,8 +287,71 @@ Set-GitHubConfiguration -LogRequestBody

----------

### Pipeline Support

This module has comprehensive support for the PowerShell pipeline. It is imperative that all
new functionality added to the module embraces this design.

* Most functions are declared as a `filter`. This is the equivalent of a `function` where the
body of the function is the `process` block, and the `begin/end` blocks are empty.

* In limited cases where one of the inputs is an array of something, and you specifically want that
to be processed as a single command (like adding a bunch of labels to a single issue at once),
you can implement it as a `function` where you use `begin/process` to gather all of the values
into a single internal array, and then do the actual command execution in the `end` block. A
good example of that which you can follow can be seen with `Add-GitHubIssueLabel`.

* Any function that requires the repo's `Uri` to be provided should be additionally aliased with
`[Alias('RepositoryUrl')]` and its `[Parameter()]` definition should include `ValueFromPipelineByPropertyName`.

* Do not use any generic term like `Name` in your parameters. That will end up causing unintended
pipeline issues down the line. For instance, if it's a label, call it `Label`, even though `Name`
would make sense, other objects in the pipeline (like a `GitHub.Respository` object) also have
a `name` property that would conflict.

* You should plan on adding additional properties to all objects being returned from an API call.
Any object that is specific to a repository should have a `RepositoryUrl` `NoteProperty` added
to it, enabling it to be piped-in to any other command that requires knowing which repository
you're talking about. Additionally, any other property that might be necessary to uniquely
identify that object in a different command should get added properties. For example, with Issues,
we add both an `IssueNumber` property and an `IssueId` property to it, as the Issue commands
need to interact with the `IssueNumber` while the Event commands interact with the `IssueId`.
We prefer to _only_ add additional properties that are believed to be needed as input to other
commands (as opposed to creating alias properties for all of the object's properties).

* For every major file, you will find an `Add-GitHub*AdditionalProperties` filter method at the end.
If you're writing a new file, you'll need to create this yourself (and model it after an existing
one). The goal of this is that you can simply pipe the output of your `Invoke-GHRestMethod`
directly into this method to update the result with the additional properties, and then return
that modified version to the user. The benefit of this approach is that you can then apply that
filter on child objects within the primary object. For instance, a `GitHub.Issue` has multiple
`GitHub.User` objects, `GitHub.Label` objects, a `GitHub.Milestone` object and more. Within
`Add-GitHubIssueAdditionalProperties`, it just needs to know to call the appropriate
`Add-GitHub*AdditionalProperties` method on the qualifying child properties, without needing to
know anything more about them.

* That method will also "type" information to each object. This is forward-looking work to ease
support for providing formatting of various object types in the future. That type should be
defined at the top of the current file at the script level (see other files for an example),
and you should be sure to both specify it in the `.OUTPUTS` section of the Comment Based Help (CBH)
for the command, as well as with `[OutputType({$script:GitHubUserTypeName})]` (for example).

* Going along with the `.OUTPUTS` is the `.INPUTS` section. Please maintain this section as well.
If you add any new type that will gain a `RepositoryUrl` property, then you'll need to update
virtually _all_ of the `.INPUTS` entries across all of the files where the function has a `Uri`
parameter. Please keep these type names alphabetical.

* To enable debugging issues involving pipeline support, there is an additional configuration
property that you might use: `Set-GitHubConfiguration -DisablePipelineSupport`. That will
prevent the module from adding _any_ additional properties to the objects.

----------

### Testing
[![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)
[![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)
[![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)


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

#### Automated Tests
[![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)
[![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)
[![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)

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

> NOTE: We're currently encountering issues with the tests successfully running within the pipeline.
> They do complete successfully locally, so please test your changes locally before submitting a
> pull request.
> Your change must successfully pass all tests before they will be merged. While we will run a CI
> build on your behalf for any submitted pull request, it's to your benefit to verify your changes
> locally first.

#### New Test Guidelines
Your tests should have NO dependencies on an account being set up in a specific way. They should
Expand Down
26 changes: 21 additions & 5 deletions GitHubAnalytics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ function Group-GitHubIssue
The date property that should be inspected when determining which week grouping the issue
if part of.

.INPUTS
GitHub.Issue

.OUTPUTS
[PSCustomObject[]] Collection of issues and counts, by week, along with the total count of issues.
[PSCustomObject[]]
Collection of issues and counts, by week, along with the total count of issues.

.EXAMPLE
$issues = @()
Expand Down Expand Up @@ -90,8 +94,12 @@ function Group-GitHubIssue
foreach ($week in $weekDates)
{
$filteredIssues = @($Issue | Where-Object {
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek))
(($DateType -eq 'Created') -and
($_.created_at -ge $week) -and
($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Closed') -and
($_.closed_at -ge $week) -and
($_.closed_at -le $endOfWeek))
})

$endOfWeek = $week
Expand Down Expand Up @@ -144,6 +152,9 @@ function Group-GitHubPullRequest
The date property that should be inspected when determining which week grouping the
pull request if part of.

.INPUTS
GitHub.PullRequest

.OUTPUTS
[PSCustomObject[]] Collection of pull requests and counts, by week, along with the
total count of pull requests.
Expand Down Expand Up @@ -211,8 +222,12 @@ function Group-GitHubPullRequest
foreach ($week in $weekDates)
{
$filteredPullRequests = @($PullRequest | Where-Object {
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek))
(($DateType -eq 'Created') -and
($_.created_at -ge $week) -and
($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Merged') -and
($_.merged_at -ge $week) -and
($_.merged_at -le $endOfWeek))
})

$endOfWeek = $week
Expand Down Expand Up @@ -265,6 +280,7 @@ function Get-WeekDate
Get-WeekDate -Weeks 10
#>
[CmdletBinding()]
[OutputType([DateTime[]])]
param(
[ValidateRange(0, 10000)]
[int] $Weeks = 12
Expand Down
Loading