-
Notifications
You must be signed in to change notification settings - Fork 32
V2.2.0 #47
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
base: master
Are you sure you want to change the base?
V2.2.0 #47
Changes from 23 commits
bc666a7
91b6566
67620f0
3cd58ed
394f93f
929a018
a55d1ee
a376c7a
966853e
59abe03
69cf6d4
223c48f
a4c4c7b
348721e
a6092a7
7788189
f35fe21
c5b0295
629bb61
be2b512
343458f
5bc19a1
26fa095
9aa47de
b4a100a
a9410ee
df509a2
9476365
8626229
5830938
0a8f5ea
50ba270
980ec06
96030fd
38e6238
5e12799
734e098
6e253b5
190b097
c22ec01
bf07568
8591b30
eb49fa1
f95d241
0b91d7e
84e5c1d
a43734a
89fb9a6
4187e34
343e7f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from lib.base import BaseGithubAction | ||
|
||
__all__ = [ | ||
'AddRepositoryCollaboratorAction' | ||
] | ||
|
||
|
||
class AddRepositoryCollaboratorAction(BaseGithubAction): | ||
def run(self, api_user, owner, repo, username, github_type, permission): | ||
|
||
enterprise = self._is_enterprise(github_type) | ||
|
||
if api_user: | ||
self.token = self._get_user_token(api_user, enterprise) | ||
|
||
payload = {"permission": permission} | ||
|
||
response = self._request("PUT", | ||
"/repos/{}/{}/collaborators/{}".format(owner, repo, username), | ||
payload, | ||
self.token, | ||
enterprise) | ||
|
||
results = {'response': response} | ||
|
||
return results |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||
--- | ||||||
name: add_repository_collaborator | ||||||
runner_type: python-script | ||||||
pack: github | ||||||
description: > | ||||||
Add a repository collaborator. | ||||||
Example: | ||||||
st2 run github.add_repository_collaborator owner="organization" repo="reponame" username="collaborator" api_user="token_name" | ||||||
enabled: true | ||||||
entry_point: add_repository_collaborator.py | ||||||
parameters: | ||||||
api_user: | ||||||
type: "string" | ||||||
description: "The API user" | ||||||
default: "{{action_context.api_user|default(None)}}" | ||||||
owner: | ||||||
type: "string" | ||||||
description: "The account owner of the repository. The name is not case sensitive.." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
required: true | ||||||
repo: | ||||||
type: "string" | ||||||
description: "The name of the repository. The name is not case sensitive." | ||||||
required: true | ||||||
username: | ||||||
type: "string" | ||||||
description: "The handle for the GitHub user account." | ||||||
required: true | ||||||
github_type: | ||||||
type: "string" | ||||||
description: "The type of github installation to target, if unset will use the configured default." | ||||||
enum: | ||||||
- "online" | ||||||
- "enterprise" | ||||||
default: "enterprise" | ||||||
permission: | ||||||
type: "string" | ||||||
description: "The permission to grant the collaborator. Only valid on organization-owned repositories. In addition to the enumerated values, you can also specify a custom repository role name, if the owning organization has defined any." | ||||||
enum: | ||||||
- "pull" | ||||||
- "push" | ||||||
- "admin" | ||||||
- "maintain" | ||||||
- "triage" | ||||||
default: "push" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from lib.base import BaseGithubAction | ||
|
||
__all__ = [ | ||
'AddUpdateRepositoryTeamAction' | ||
] | ||
|
||
|
||
class AddUpdateRepositoryTeamAction(BaseGithubAction): | ||
def run(self, api_user, org, team_slug, | ||
owner, repo, github_type, permission): | ||
|
||
enterprise = self._is_enterprise(github_type) | ||
|
||
if api_user: | ||
self.token = self._get_user_token(api_user, enterprise) | ||
|
||
payload = {"permission": permission} | ||
|
||
response = self._request("PUT", | ||
"/orgs/{}/teams/{}/repos/{}/{}".format(org, team_slug, owner, repo), | ||
payload, | ||
self.token, | ||
enterprise) | ||
|
||
results = {'response': response} | ||
|
||
return results |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
name: add_update_repository_team | ||
runner_type: python-script | ||
pack: github | ||
description: > | ||
Add or update repository team. | ||
Example: | ||
st2 run github.add_update_repository_team organization="organization" owner="owner" repo="reponame" team_slug="team_id" api_user="token_name" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example uses a parameter called organization, but the yaml states that the parameter is called org. |
||
enabled: true | ||
entry_point: add_update_repository_team.py | ||
parameters: | ||
api_user: | ||
type: "string" | ||
description: "The API user" | ||
default: "{{action_context.api_user|default(None)}}" | ||
org: | ||
type: "string" | ||
description: "The organization name. The name is not case sensitive." | ||
required: true | ||
team_slug: | ||
type: "string" | ||
description: "The slug of the team name." | ||
required: true | ||
owner: | ||
type: "string" | ||
description: "The account owner of the repository. The name is not case sensitive." | ||
required: true | ||
repo: | ||
type: "string" | ||
description: "The name of the repository. The name is not case sensitive." | ||
required: true | ||
github_type: | ||
type: "string" | ||
description: "The type of github installation to target, if unset will use the configured default." | ||
enum: | ||
- "online" | ||
- "enterprise" | ||
default: "enterprise" | ||
permission: | ||
type: "string" | ||
description: "The permission to grant the team on this repository. In addition to the enumerated values, you can also specify a custom repository role name, if the owning organization has defined any. If no permission is specified, the team's permission attribute will be used to determine what permission to grant the team on this repository." | ||
enum: | ||
- "pull" | ||
- "push" | ||
- "admin" | ||
- "maintain" | ||
- "triage" | ||
default: "push" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from lib.base import BaseGithubAction | ||
|
||
__all__ = [ | ||
'CheckTeamPermissionsForRepository' | ||
] | ||
|
||
|
||
class CheckTeamPermissionsForRepository(BaseGithubAction): | ||
def run(self, api_user, org, team_slug, owner, repo, github_type): | ||
|
||
enterprise = self._is_enterprise(github_type) | ||
|
||
if api_user: | ||
self.token = self._get_user_token(api_user, enterprise) | ||
|
||
try: | ||
self._request("GET", | ||
"/orgs/{}/teams/{}/repos/{}/{}".format(org, team_slug, owner, repo), | ||
{}, | ||
self.token, | ||
enterprise) | ||
|
||
results = { | ||
'response': "The team {} has access to the repository {}".format(team_slug, repo) | ||
} | ||
except OSError as err: | ||
raise err | ||
except ValueError as err: | ||
raise err | ||
except Exception as err: | ||
if str(err).find("404"): | ||
results = {'response': "The team don't have access to the repository or not found"} | ||
else: | ||
raise err | ||
return results |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: check_team_permissions_for_repository | ||
runner_type: python-script | ||
pack: github | ||
description: > | ||
Check team permissions for a repository. | ||
Example: | ||
st2 run github.check_team_permissions_for_repository organization="organization" owner="owner" repo="reponame" team_slug="team_id" api_user="token_name" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example uses parameter organization, but yaml states parameter is called org - so these don't match. |
||
enabled: true | ||
entry_point: check_team_permissions_for_repository.py | ||
parameters: | ||
api_user: | ||
type: "string" | ||
description: "The API user" | ||
default: "{{action_context.api_user|default(None)}}" | ||
org: | ||
type: "string" | ||
description: "The organization name. The name is not case sensitive." | ||
required: true | ||
team_slug: | ||
type: "string" | ||
description: "The slug of the team name." | ||
required: true | ||
owner: | ||
type: "string" | ||
description: "The account owner of the repository. The name is not case sensitive." | ||
required: true | ||
repo: | ||
type: "string" | ||
description: "The name of the repository. The name is not case sensitive." | ||
required: true | ||
github_type: | ||
type: "string" | ||
description: "The type of github installation to target, if unset will use the configured default." | ||
enum: | ||
- "online" | ||
- "enterprise" | ||
default: "enterprise" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from lib.base import BaseGithubAction | ||
|
||
__all__ = [ | ||
'CheckIfUserIsRepositoryCollaborator' | ||
] | ||
|
||
|
||
class CheckIfUserIsRepositoryCollaborator(BaseGithubAction): | ||
def run(self, api_user, owner, repo, username, github_type): | ||
|
||
enterprise = self._is_enterprise(github_type) | ||
|
||
if api_user: | ||
self.token = self._get_user_token(api_user, enterprise) | ||
|
||
try: | ||
self._request("GET", | ||
"/repos/{}/{}/collaborators/{}".format(owner, repo, username), | ||
{}, | ||
self.token, | ||
enterprise) | ||
results = {'response': "The user {} is a Collaborator".format(username)} | ||
except OSError as err: | ||
raise err | ||
except ValueError as err: | ||
raise err | ||
except Exception as err: | ||
if str(err).find("404"): | ||
results = {'response': "is not a Collaborator or not found"} | ||
else: | ||
raise err | ||
return results |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
name: check_user_repository_collaborator | ||
runner_type: python-script | ||
pack: github | ||
description: > | ||
Check if a user is a repository collaborator. | ||
Example: | ||
st2 run github.check_user_repository_collaborator owner="organization" repo="reponame" username="collaborator" api_user="token_name" | ||
enabled: true | ||
entry_point: check_user_repository_collaborator.py | ||
parameters: | ||
api_user: | ||
type: "string" | ||
description: "The API user" | ||
default: "{{action_context.api_user|default(None)}}" | ||
owner: | ||
type: "string" | ||
description: "The account owner of the repository. The name is not case sensitive." | ||
required: true | ||
repo: | ||
type: "string" | ||
description: "The name of the repository. The name is not case sensitive." | ||
required: true | ||
username: | ||
type: "string" | ||
description: "The handle for the GitHub user account." | ||
required: true | ||
github_type: | ||
type: "string" | ||
description: "The type of github installation to target, if unset will use the configured default." | ||
enum: | ||
- "online" | ||
- "enterprise" | ||
default: "enterprise" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from lib.base import BaseGithubAction | ||
|
||
__all__ = [ | ||
'CreateBranchAction' | ||
] | ||
|
||
|
||
class CreateBranchAction(BaseGithubAction): | ||
def run(self, api_user, new_branch, origin_ref, repository, github_type): | ||
|
||
enterprise = self._is_enterprise(github_type) | ||
|
||
if api_user: | ||
self.token = self._get_user_token(api_user, enterprise) | ||
|
||
# First, we have to get the sha1 for the given origin ref | ||
response = self._request("GET", f"/repos/{repository}/git/ref/{origin_ref}", | ||
{}, | ||
self.token, | ||
enterprise) | ||
|
||
if not response or not response['object']['sha']: | ||
raise Exception(f"Could not get ref [{origin_ref}]. Response: {response}") | ||
|
||
# Then, we create the branch based on the origin ref | ||
payload = {"ref": f"refs/heads/{new_branch}", | ||
"sha": response['object']['sha']} | ||
|
||
response = self._request("POST", | ||
f"/repos/{repository}/git/refs", | ||
payload, | ||
self.token, | ||
enterprise) | ||
|
||
return {'response': response} |
Uh oh!
There was an error while loading. Please reload this page.