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

V2.2.0 #47

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bc666a7
3 new actions
MarlonHeiber May 23, 2022
91b6566
Update CHANGES.md
MarlonHeiber May 23, 2022
67620f0
more two actions
MarlonHeiber May 25, 2022
3cd58ed
Merge branch 'repositoryActions' of github.com:MarlonHeiber/stackstor…
MarlonHeiber May 25, 2022
394f93f
create/get/delete branches :)
pimguilherme Jun 21, 2022
929a018
documentation
pimguilherme Jun 21, 2022
a55d1ee
fixes
pimguilherme Jun 22, 2022
a376c7a
adding missing repository actions
pimguilherme Jun 24, 2022
966853e
pack
MarlonHeiber Jul 12, 2022
59abe03
pack 2.2.0
MarlonHeiber Jul 12, 2022
69cf6d4
Merge branch 'v2.1.2' into repositoryActions
MarlonHeiber Jul 18, 2022
223c48f
Merge pull request #1 from MarlonHeiber/repositoryActions
MarlonHeiber Jul 18, 2022
a4c4c7b
Merge pull request #2 from MarlonHeiber/create-branch-action
MarlonHeiber Jul 18, 2022
348721e
Merge branch 'master' into v2.2.0
MarlonHeiber Jul 18, 2022
a6092a7
changeloh
MarlonHeiber Jul 18, 2022
7788189
Squashed 'lint-configs/' content from commit 4696bad
MarlonHeiber Jul 18, 2022
f35fe21
Merge commit '7788189fe660bd4b8e6eea0e85d69d29efc32c1d' as 'lint-conf…
MarlonHeiber Jul 18, 2022
c5b0295
lint_flake8
MarlonHeiber Jul 18, 2022
629bb61
lint
MarlonHeiber Jul 18, 2022
be2b512
variable not used
MarlonHeiber Jul 19, 2022
343458f
pylint test
MarlonHeiber Jul 19, 2022
5bc19a1
pylint
MarlonHeiber Jul 19, 2022
26fa095
update readme
MarlonHeiber Jul 21, 2022
9aa47de
adding missing actions :)
pimguilherme Aug 2, 2022
b4a100a
Merge pull request #5 from MarlonHeiber/fix/add-missing-actions
pimguilherme Aug 2, 2022
a9410ee
adding missing actions :)
pimguilherme Aug 2, 2022
df509a2
Merge pull request #6 from MarlonHeiber/fix/add-missing-action
pimguilherme Aug 2, 2022
9476365
minor merge adjustments
pimguilherme Aug 2, 2022
8626229
Merge branch 'master' into v2.2.0
pimguilherme Aug 2, 2022
5830938
adding environment creation functionality
pimguilherme Aug 11, 2022
0a8f5ea
removing unnecessary lint-config changes
pimguilherme Nov 10, 2022
50ba270
Update CHANGES.md
pimguilherme Nov 10, 2022
980ec06
adjusting add/update environment documentation
pimguilherme Nov 10, 2022
96030fd
adjusting typos
pimguilherme Nov 10, 2022
38e6238
fixing typo
pimguilherme Nov 10, 2022
5e12799
making github_type usage/doc uniform
pimguilherme Nov 10, 2022
734e098
Merge branch 'v2.2.0' of github.com:MarlonHeiber/stackstorm-github in…
pimguilherme Nov 10, 2022
6e253b5
fixing typos :)
pimguilherme Nov 10, 2022
190b097
Merge branch 'master' into v2.2.0
pimguilherme Nov 11, 2022
c22ec01
adding missing action to doc
pimguilherme Nov 11, 2022
bf07568
fixing tpos
pimguilherme Nov 11, 2022
8591b30
typo
pimguilherme Nov 11, 2022
eb49fa1
description
pimguilherme Nov 11, 2022
f95d241
adjusting text
pimguilherme Nov 11, 2022
0b91d7e
adjusting doc
pimguilherme Nov 11, 2022
84e5c1d
adjusting action
pimguilherme Nov 11, 2022
a43734a
Merge branch 'v2.2.0' of github.com:MarlonHeiber/stackstorm-github in…
pimguilherme Nov 11, 2022
89fb9a6
typo
pimguilherme Nov 11, 2022
4187e34
adjusting docs
pimguilherme Nov 11, 2022
343e7f5
update changelog
pimguilherme Nov 11, 2022
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
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 2.2.0
* Add new ``github.add_repository_collaborator`` action which allows user to add a collaborator to repository.
* Add new ``github.check_user_repository_collaborator`` action which allows user to check if an user is a collaborator's repository.
* Add new ``github.get_repository_collaborators`` action which allows user to list the collaborators of repository.
* Add new ``github.add_update_repository_team`` action which allows user to add a team to repository.
* Add new ``github.check_team_permissions_for_repository`` action which allows user to check if a team has access to repository.
* Add new ``github.create_organization_repository`` action which allows user to create an organization repository.
* Add new ``github.create_repository_authenticated_user`` action which allows user to create an user repository.
* Add new ``github.create_repository_from_template`` action which allows user to create a repository from template.
* Bug fix on ``github.store_oauth_token.`` to api save the token correctly so that it can be read later.
* Segure improvement on ``github.store_oauth_token.`` to encrypt de github token in web interface.
pimguilherme marked this conversation as resolved.
Show resolved Hide resolved
* Add new ``github.create_branch``, ``github.get_branch``, ``github.delete_branch`` actions which allows user to create/get/delete a branch.
* Add token to ``github.create_file``, ``github.create_pull``, ``github.update_file``.

## 2.1.1

* Bug fix (#43) where the sensor will throw an exception if no events are returned from the GitHub api.
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,27 @@ StackStorm webhook handler.
## Actions

* ``add_comment`` - Add comment to the provided issue / pull request.
* ``add_repository_collaborator`` - Add a collaborator to repository.
* ``add_status`` - Add commit status to the provided commit.
* ``add_update_repository_team`` - Add/Update a team to repository.
* ``create_branch`` - Create new branch.
* ``create_file`` - Create new file.
* ``create_issue`` - Create a new issue.
* ``create_repository_authenticated_user`` - Create an user repository.
* ``create_repository_from_template`` - Create a repository from template.
* ``create_organization_repository`` - Create an organization repository.
* ``create_pull`` - Create a new Pull Request.
* ``check_team_permissions_for_repository`` - Check if a team has access to repository.
* ``check_user_repository_collaborator`` - Check if an user is a collaborator's repository.
* ``delete_branch`` - Remove branch.
* ``delete_branch_protection`` - Remove branch protection settings.
* ``get_branch`` - Get branch.
* ``get_branch_protection`` - Get branch protection settings.
* ``get_contents`` - Get repository or file contents.
* ``get_issue`` - Retrieve information about a particular issue. Note: You
only need to specify authentication token in the config if you use this
action with a private repository.
* ``get_repository_collaborators`` - List the collaborators of repository.
* ``list_issues`` - List all the issues for a particular repo (includes pull
requests since pull requests are just a special type of issues).
* ``list_pulls`` - List all pull requests for a particular repo.
Expand Down
26 changes: 26 additions & 0 deletions actions/add_repository_collaborator.py
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
44 changes: 44 additions & 0 deletions actions/add_repository_collaborator.yaml
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.."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: "The account owner of the repository. The name is not case sensitive.."
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"
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"
27 changes: 27 additions & 0 deletions actions/add_update_repository_team.py
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
48 changes: 48 additions & 0 deletions actions/add_update_repository_team.yaml
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"

Choose a reason for hiding this comment

The 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"
35 changes: 35 additions & 0 deletions actions/check_team_permissions_for_repository.py
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
38 changes: 38 additions & 0 deletions actions/check_team_permissions_for_repository.yaml
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"

Choose a reason for hiding this comment

The 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"
32 changes: 32 additions & 0 deletions actions/check_user_repository_collaborator.py
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
34 changes: 34 additions & 0 deletions actions/check_user_repository_collaborator.yaml
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"
35 changes: 35 additions & 0 deletions actions/create_branch.py
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}
Loading