microsoft / PowerShellForGitHub

Microsoft PowerShell wrapper for GitHub API
Other
582 stars 184 forks source link

Added Discussions support #382

Closed variableresistor closed 1 year ago

variableresistor commented 1 year ago

Description

Allow the user to enable Discussions in Github repositories

Issues Fixed

Fixes #378

References

https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#update-a-repository

Checklist

variableresistor commented 1 year ago

Turns out unit tests aren't working. My mistake. Getting: [-] Context GitHubRepositories\New-GitHubRepository.When creating a repository for the authenticated user.When creating a private repository with default settings failed [0] HttpResponseException: Response status code does not indicate success: 404 (Not Found). at Invoke-GHRestMethod, C:\Repos\PowerShellForGitHub\GitHubCore.ps1:320 at Remove-GitHubRepository, C:\Repos\PowerShellForGitHub\GitHubRepositories.ps1:525 at , C:\Repos\PowerShellForGitHub\Tests\GitHubRepositories.tests.ps1:103 [1] HttpResponseException: Response status code does not indicate success: 500 (Internal Server Error). at Invoke-GHRestMethod, C:\Repos\PowerShellForGitHub\GitHubCore.ps1:320 at New-GitHubRepository, C:\Repos\PowerShellForGitHub\GitHubRepositories.ps1:233 at , C:\Repos\PowerShellForGitHub\Tests\GitHubRepositories.tests.ps1:77 [-] Context GitHubRepositories\New-GitHubRepository.When creating an organization repository.When creating a public repository with default settings failed [0] HttpResponseException: Response status code does not indicate success: 404 (Not Found). at Invoke-GHRestMethod, C:\Repos\PowerShellForGitHub\GitHubCore.ps1:320 at Remove-GitHubRepository, C:\Repos\PowerShellForGitHub\GitHubRepositories.ps1:525 at , C:\Repos\PowerShellForGitHub\Tests\GitHubRepositories.tests.ps1:253 [1] HttpResponseException: Response status code does not indicate success: 404 (Not Found). at Invoke-GHRestMethod, C:\Repos\PowerShellForGitHub\GitHubCore.ps1:320 at New-GitHubRepository, C:\Repos\PowerShellForGitHub\GitHubRepositories.ps1:233 at , C:\Repos\PowerShellForGitHub\Tests\GitHubRepositories.tests.ps1:226 [-] Context GitHubRepositories\New-GitHubRepository.When creating an organization repository.When creating a private repository with default settings failed [0] HttpResponseException: Response status code does not indicate success: 404 (Not Found). at Invoke-GHRestMethod, C:\Repos\PowerShellForGitHub\GitHubCore.ps1:320 at Remove-GitHubRepository, C:\Repos\PowerShellForGitHub\GitHubRepositories.ps1:525 at , C:\Repos\PowerShellForGitHub\Tests\GitHubRepositories.tests.ps1:292 [1] HttpResponseException: Response status code does not indicate success: 404 (Not Found). at Invoke-GHRestMethod, C:\Repos\PowerShellForGitHub\GitHubCore.ps1:320 at New-GitHubRepository, C:\Repos\PowerShellForGitHub\GitHubRepositories.ps1:233 at , C:\Repos\PowerShellForGitHub\Tests\GitHubRepositories.tests.ps1:266

Strangely, some tests are still passing: Tests completed in 33.74s Tests Passed: 9, Failed: 6, Skipped: 0 NotRun: 133 BeforeAll \ AfterAll failed: 3

variableresistor commented 1 year ago

Works okay when I run this:

$Repo = New-GitHubRepository -Name (New-Guid) -Discussions
$Repo.has_discussions
True

Been going in circles on this for an hour. Read all the contributing docs in the repo. Doesn't even work when I revert my change.

HowardWolosky commented 1 year ago

Been going in circles on this for an hour. Read all the contributing docs in the repo. Doesn't even work when I revert my change.

It looks like you're not sync'd up with what's currently in main.

variableresistor commented 1 year ago

Been going in circles on this for an hour. Read all the contributing docs in the repo. Doesn't even work when I revert my change.

It looks like you're not sync'd up with what's currently in main.

Yeah, that makes sense; I'm probably not getting all the Pester 5+ changes. My repo says it's up to date with the main branch, but it's clearly not. So can I just close out this PR, re-create my fork, then open a new one?

HowardWolosky commented 1 year ago

Yeah, that makes sense; I'm probably not getting all the Pester 5+ changes. My repo says it's up to date with the main branch, but it's clearly not. So can I just close out this PR, re-create my fork, then open a new one?

That's overkill. No need to do that. You just need to merge the current changes in master .

First, add a named branch for upstream:

git remote add upstream https://github.com/microsoft/PowerShellForGitHub.git

After that, it's easy to do operations in your fork that interact with this project. This will get your fork's master fully in-sync with this one.

git checkout master
git pull upstream master
git push

Finally, just rebase your branch on top of your local master

git checkout <your local branch name>
git rebase master
git push -f

After that, your fork will be modifying on top of the current change in this project's master.

variableresistor commented 1 year ago

@HowardWolosky okay, my change is actually working here. It's in the context "When creating a repository with all possible settings". It's the context "When creating a private repository with default settings" that's not working. It uses the same function to run both, but my new -Discussions parameter isn't even being added to the header. So I'm starting to believe it's a different issue. Here's some relevent variables I inspected during the test run:

$params
Name                           Value
----                           -----
TelemetryEventName             New-GitHubRepository
Method                         Post
UriFragment                    user/repos
AcceptHeader                   application/vnd.github.baptiste-preview+json
TelemetryProperties            {RepositoryName}
Body                           {…
Description                    Creating 359474aa-4bfa-4fc2-8718-d60b1bea7626
AccessToken

PS C:\Repos\PowerShellForGitHub> $params.Body
{
  "name": "359474aa-4bfa-4fc2-8718-d60b1bea7626",
  "private": true
}

Line 222 in GitHubRepositories.ps1 while running Context -Name 'When creating a private repository with default settings'

Error: HttpResponseException: Response status code does not indicate success: 500 (Internal Server Error)

HowardWolosky commented 1 year ago

I'm not seeing the test failures that you're describing when running your changes locally.

X-Guardian commented 1 year ago

This parameter should also be added to the Set-GitHubRepository function.

ghost commented 1 year ago

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 14 days of this comment.

variableresistor commented 1 year ago

This parameter should also be added to the Set-GitHubRepository function.

This would make sense, but the GitHub docs don't show has_discussions as a parameter to update a repository.

X-Guardian commented 1 year ago

No, but it does work (I tried it). I think the documentation is incomplete.

variableresistor commented 1 year ago

No, but it does work (I tried it). I think the documentation is incomplete.

I pushed the change right before I saw your comment. Changing the other as well.

HowardWolosky commented 1 year ago

/azp run PowerShellForGitHub-CI

azure-pipelines[bot] commented 1 year ago
Azure Pipelines successfully started running 1 pipeline(s).