Skip to content
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

feat: Secret Scanning + Code completion + User Migration #1111

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 66 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);

// see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html
namespace PHPSTORM_META {

override(\Github\Client::api(0), map([
"me" => \Github\Api\CurrentUser::class,
"current_user" => \Github\Api\CurrentUser::class,
"currentUser" => \Github\Api\CurrentUser::class,
"codeOfConduct" => \Github\Api\Miscellaneous\CodeOfConduct::class,
"deployment" => \Github\Api\Deployment::class,
"deployments" => \Github\Api\Deployment::class,
"ent" => \Github\Api\Enterprise::class,
"enterprise" => \Github\Api\Enterprise::class,
"emojis" => \Github\Api\Miscellaneous\Emojis::class,
"git" => \Github\Api\GitData::class,
"git_data" => \Github\Api\GitData::class,
"gitData" => \Github\Api\GitData::class,
"gist" => \Github\Api\Gists::class,
"gists" => \Github\Api\Gists::class,
"gitignore" => \Github\Api\Miscellaneous\Gitignore::class,
"apps" => \Github\Api\Apps::class,
"issue" => \Github\Api\Issue::class,
"issues" => \Github\Api\Issue::class,
"markdown" => \Github\Api\Markdown::class,
"licenses" => \Github\Api\Miscellaneous\Licenses::class,
"notification" => \Github\Api\Notification::class,
"notifications" => \Github\Api\Notification::class,
"organization" => \Github\Api\Organization::class,
"organizations" => \Github\Api\Organization::class,
"org_project" => \Github\Api\Organization\Projects::class,
"orgProject" => \Github\Api\Organization\Projects::class,
"org_projects" => \Github\Api\Organization\Projects::class,
"orgProjects" => \Github\Api\Organization\Projects::class,
"organization_project" => \Github\Api\Organization\Projects::class,
"organizationProject" => \Github\Api\Organization\Projects::class,
"organization_projects" => \Github\Api\Organization\Projects::class,
"organizationProjects" => \Github\Api\Organization\Projects::class,
"pr" => \Github\Api\PullRequest::class,
"pulls" => \Github\Api\PullRequest::class,
"pullRequest" => \Github\Api\PullRequest::class,
"pull_request" => \Github\Api\PullRequest::class,
"pullRequests" => \Github\Api\PullRequest::class,
"pull_requests" => \Github\Api\PullRequest::class,
"rateLimit" => \Github\Api\RateLimit::class,
"rate_limit" => \Github\Api\RateLimit::class,
"repo" => \Github\Api\Repo::class,
"repos" => \Github\Api\Repo::class,
"repository" => \Github\Api\Repo::class,
"repositories" => \Github\Api\Repo::class,
"search" => \Github\Api\Search::class,
"team" => \Github\Api\Organization\Teams::class,
"teams" => \Github\Api\Organization\Teams::class,
"member" => \Github\Api\Organization\Members::class,
"members" => \Github\Api\Organization\Members::class,
"user" => \Github\Api\User::class,
"users" => \Github\Api\User::class,
"authorization" => \Github\Api\Authorizations::class,
"authorizations" => \Github\Api\Authorizations::class,
"meta" => \Github\Api\Meta::class,
"graphql" => \Github\Api\GraphQL::class,
"outsideCollaborators" => \Github\Api\Organization\OutsideCollaborators::class,
"outside_collaborators" => \Github\Api\Organization\OutsideCollaborators::class,
]));
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/h

## Advanced install

We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).
We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).

### Using a different http client

Expand All @@ -53,6 +53,14 @@ $client = Client::createWithHttpClient(new HttplugClient());

Read more about [using different clients in our docs](doc/customize.md).

## Code Completion (JetBrains PhpStorm)
To improve code-completion and ux approach in PhpStorm, advanced metadata is now added.

![Auto-Complete Api Names](https://user-images.githubusercontent.com/1327607/229752632-f1e4a1b3-a9f8-48be-9beb-d41927e96cde.png)

![Auto-Complete Api Methods](https://user-images.githubusercontent.com/1327607/229752677-3a2f3dc8-51d7-45b7-a7d0-0cde7ac145f7.png)


## Framework integrations

### Laravel
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"php-http/discovery": true
}
}
}
5 changes: 5 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v3 APIs:
* [Public keys](currentuser/publickeys.md)
* [Memberships](currentuser/memberships.md)
* [Enterprise](enterprise.md)
* [Secret Scanning Alert](enterprise/secret-scanning.md)
* [Gists](gists.md)
* [Comments](gists/comments.md)
* GitData
Expand Down Expand Up @@ -42,6 +43,7 @@ v3 APIs:
* [Self hosted runners](organization/actions/self_hosted_runners.md)
* [Secrets](organization/actions/secrets.md)
* [Variables](organization/actions/variables.md)
* [Secret Scanning Alert](organization/secret-scanning.md)
* [Projects](project/projects.md)
* [Columns](project/columns.md)
* [Cards](project/cards.md)
Expand Down Expand Up @@ -74,8 +76,10 @@ v3 APIs:
* [Stargazers](repo/stargazers.md)
* [Statuses](repo/statuses.md)
* [Tags](repo/tags.md)
* [Secret Scanning Alert](repo/secret-scanning.md)
* [Search](search.md)
* [Users](users.md)
* [Migrations](user/migration.md)

Additional features:

Expand All @@ -86,3 +90,4 @@ Additional features:
* [Request / Response info](request_response_info.md)
* [Pagination support](result_pager.md)
* [Request any Route](request_any_route.md)

10 changes: 10 additions & 0 deletions doc/enterprise/secret-scanning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Enterprise / Secret Scanning API
[Back to the "Enterprise API"](../../enterprise.md) | [Back to the navigation](../../README.md)

# List secret-scanning alerts for an Enterprise

https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-enterprise

```php
$alerts = $client->api('enterprise')->secretScanning()->alerts('KnpLabs');
```
10 changes: 10 additions & 0 deletions doc/organization/secret-scanning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Organization / Secret Scanning API
[Back to the "Organization API"](../../organization.md) | [Back to the navigation](../../README.md)

# List secret-scanning alerts for an Organization

https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-organization

```php
$alerts = $client->api('organization')->secretScanning()->alerts('KnpLabs');
```
8 changes: 8 additions & 0 deletions doc/pull_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ $pullRequest = $client->api('pull_request')->create('ezsystems', 'ezpublish', ar
```

This returns the details of the pull request.

### Merge a Pull Request

> Requires [authentication](security.md)

```php
$client->api('pull_request')->merge('KnpLabs', 'php-github-api', $pullNumber, $commitMessage, $sha, $mergeMethod, $commitTitle);
```
38 changes: 38 additions & 0 deletions doc/repo/secret-scanning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Repository / Secret Scanning API
[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md)

# List secret-scanning alerts for a repository

https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-a-repository

```php
$alerts = $client->api('repos')->secretScanning()->alerts('KnpLabs', 'php-github-api');
```

# Get a secret-scanning alert

https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#get-a-secret-scanning-alert

```php
$alert = $client->api('repos')->secretScanning()->getAlert('KnpLabs', 'php-github-api', $alertNumber);
```

# Update a secret-scanning alert

https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#update-a-secret-scanning-alert

```php
$client->api('repos')->secretScanning()->updateAlert('KnpLabs', 'php-github-api', $alertNumber, [
'state' => 'resolved',
'resolution' => 'wont-fix'
]);
```

# List Locations for a secret-scanning alert

https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-locations-for-a-secret-scanning-alert

```php
$locations = $client->api('repos')->secretScanning()->locations('KnpLabs', 'php-github-api', $alertNumber);
```

70 changes: 70 additions & 0 deletions doc/user/migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## User / Migrations API
[Back to the "Users API"](../../users.md) | [Back to the navigation](../../README.md)

# List user migrations

https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-user-migrations

```php
$migrations = $client->api('user')->migration()->list([
'per_page' => 10
]);
```

# Start a User Migration

https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#start-a-user-migration

```php
$client->users()->migration()->start([
'repositories' => [
'KnpLabs/php-github-api'
],
'lock_repositories' => true,
'exclude_metadata' => false,
'exclude_git_data' => false,
'exclude_attachments' => true,
'exclude_releases' => false,
'exclude_owner_projects' => true,
'org_metadata_only' => false,
'exclude' => [
'Exclude attributes from the API response to improve performance'
]
]);
```

# Get a User Migration Status

https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#get-a-user-migration-status

```php
$status = $client->user()->migration()->status(12, [
'exclude' => [
'exclude attributes'
]
]);
```

# Delete a User Migration Archive

https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#delete-a-user-migration-archive

```php
$client->user()->migration()->deleteArchive(12);
```

# Unlock a User Repository

https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#unlock-a-user-repository

```php
$client->user()->migration()->unlockRepo(12, 'php-github-api');
```

# List repositories for a User Migration

https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration

```php
$repos = $client->user()->migration()->repos(2);
```
13 changes: 13 additions & 0 deletions doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,16 @@ $emails = $client->api('current_user')->emails()->remove(array('first@provider.o
```

Return an array of the authenticated user emails.

### List repositories for the user

> Requires [authentication](security.md) for authenticated user

```php
$repos = $client->api('current_user')->repositories();
$repos = $client->api('users')->repositories();
```

> Note: Following arguments `$type`, `$sort`, `$direction`, `$visibility` and `$affiliation` are deprecated and a new array argument is added `$parameters` which can be used to pass all these existing arguments as well as parameters like `per_page` which was not supported earlier.

Return an array of the authenticated user repos.
29 changes: 22 additions & 7 deletions lib/Github/Api/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Github\Api\CurrentUser\PublicKeys;
use Github\Api\CurrentUser\Starring;
use Github\Api\CurrentUser\Watchers;
use JetBrains\PhpStorm\Deprecated;

/**
* @link http://developer.github.com/v3/users/
Expand Down Expand Up @@ -114,15 +115,29 @@ public function teams()
* @link https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user
*
* @param string $type role in the repository
* @param string $sort sort by
* @param string $direction direction of sort, asc or desc
* @param string $visibility visibility of repository
* @param string $affiliation relationship to repository
* @param string $sort sort by (Deprecated)
* @param string $direction direction of sort, asc or desc (Deprecated)
* @param string $visibility visibility of repository (Deprecated)
* @param string $affiliation relationship to repository (Deprecated)
* @param array $parameters e.g. [
* 'type' => 'owner',
* 'sort' => 'full_name',
* 'direction'=> 'asc',
* 'visibility' => null,
* 'affiliation' => null,
* 'per_page' => 50,
* ]
*
* @return array
*/
public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = null, $affiliation = null)
{
public function repositories(
$type = 'owner',
$sort = 'full_name',
$direction = 'asc',
$visibility = null,
$affiliation = null,
array $parameters = []
) {
$params = [
'type' => $type,
'sort' => $sort,
Expand All @@ -139,7 +154,7 @@ public function repositories($type = 'owner', $sort = 'full_name', $direction =
$params['affiliation'] = $affiliation;
}

return $this->get('/user/repos', $params);
return $this->get('/user/repos', array_merge($params, $parameters));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions lib/Github/Api/Enterprise.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\Enterprise\License;
use Github\Api\Enterprise\ManagementConsole;
use Github\Api\Enterprise\SecretScanning;
use Github\Api\Enterprise\Stats;
use Github\Api\Enterprise\UserAdmin;

Expand Down Expand Up @@ -48,4 +49,12 @@ public function userAdmin()
{
return new UserAdmin($this->getClient());
}

/**
* @return SecretScanning
*/
public function secretScanning(): SecretScanning
{
return new SecretScanning($this->getClient());
}
}
21 changes: 21 additions & 0 deletions lib/Github/Api/Enterprise/SecretScanning.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Github\Api\Enterprise;

use Github\Api\AbstractApi;

class SecretScanning extends AbstractApi
{
/**
* @link https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-enterprise
*
* @param string $enterprise
* @param array $params
*
* @return array|string
*/
public function alerts(string $enterprise, array $params = [])
{
return $this->get('/enterprises/'.rawurlencode($enterprise).'/secret-scanning/alerts', $params);
}
}