Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions actions/create_organization_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import time
import datetime


from lib.base import BaseGithubAction

__all__ = [
'CreateOrganizationRepositoryAction'
]


class CreateOrganizationRepositoryAction(BaseGithubAction):
def run(self, api_user, org, name, description, github_type, homepage, private, visibility,
has_issues, has_projects, has_wiki, is_template, team_id, auto_init,
gitignore_template, license_template, allow_squash_merge, allow_merge_commit,
allow_rebase_merge, allow_auto_merge, delete_branch_on_merge):

enterprise = self._is_enterprise(github_type)

if api_user:
self.token = self._get_user_token(api_user, enterprise)

payload = {"name": name,
"description": description,
"homepage": homepage,
"private": private,
"visibility": visibility,
"has_issues": has_issues,
"has_projects": has_projects,
"has_wiki": has_wiki,
"is_template": is_template,
"team_id": team_id,
"auto_init": auto_init,
"gitignore_template": gitignore_template,
"license_template": license_template,
"allow_squash_merge": allow_squash_merge,
"allow_merge_commit": allow_merge_commit,
"allow_rebase_merge": allow_rebase_merge,
"allow_auto_merge": allow_auto_merge,
"delete_branch_on_merge": delete_branch_on_merge}

response = self._request("POST",
"/orgs/{}/repos".format(org),
payload,
self.token,
enterprise)

results = {'owner': response['owner']['login']}
results['response'] = response

return results
88 changes: 88 additions & 0 deletions actions/create_organization_repository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: create_organization_repository
runner_type: python-script
pack: github
description: >
Creates a Github repository fot an organization.
Example:
st2 run github.create_organization_repository org="organization" name="reponame" description="test github.create_repository" private=true visibility="private" api_user="token_name"
enabled: true
entry_point: create_organization_repository.py
parameters:
api_user:
type: "string"
description: "The API user"
default: "{{action_context.api_user|default(None)}}"
org:
type: "string"
description: "GitHub Organization."
required: true
name:
type: "string"
description: "The name of the repository."
required: true
description:
type: "string"
description: "A short description of the repository."
github_type:
type: "string"
description: "The type of github installation to target, if unset will use the configured default."
enum:
- "online"
- "enterprise"
default: "enterprise"
homepage:
type: "string"
description: "A URL with more information about the repository."
private:
type: "boolean"
description: "Whether the repository is private."
default: true
visibility:
type: "string"
description: "Can be public or private. If your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+, visibility can also be internal. Note: For GitHub Enterprise Server and GitHub AE, this endpoint will only list repositories available to all users on the enterprise."
enum:
- "private"
- "public"
- "internal"
default: "private"
has_issues:
type: "boolean"
description: "Whether issues are enabled."
has_projects:
type: "boolean"
description: "Whether projects are enabled."
has_wiki:
type: "boolean"
description: "Whether the wiki is enabled."
is_template:
type: "boolean"
description: "Whether this repository acts as a template that can be used to generate new repositories."
default: false
team_id:
type: "integer"
description: "The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization."
auto_init:
type: "boolean"
description: "Whether the repository is initialized with a minimal README."
gitignore_template:
type: "string"
description: "The desired language or platform to apply to the .gitignore."
license_template:
type: "string"
description: "The license keyword of the open source license for this repository."
allow_squash_merge:
type: "boolean"
description: "Whether to allow squash merges for pull requests."
allow_merge_commit:
type: "boolean"
description: "Whether to allow merge commits for pull requests."
allow_rebase_merge:
type: "boolean"
description: "Whether to allow rebase merges for pull requests."
allow_auto_merge:
type: "boolean"
description: "Whether to allow Auto-merge to be used on pull requests."
delete_branch_on_merge:
type: "boolean"
description: "Whether to delete head branches when pull requests are merged"
48 changes: 48 additions & 0 deletions actions/create_repository_authenticated_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

from lib.base import BaseGithubAction

__all__ = [
'CreateRepositoryAuthenticatedUserAction'
]

class CreateRepositoryAuthenticatedUserAction(BaseGithubAction):
def run(self, api_user, user, name, description, github_type, homepage, private,
has_issues, has_projects, has_wiki, team_id, auto_init, gitignore_template,
license_template, allow_squash_merge, allow_merge_commit, allow_rebase_merge,
allow_auto_merge, delete_branch_on_merge, has_downloads, is_template, ):

enterprise = self._is_enterprise(github_type)

if api_user:
self.token = self._get_user_token(api_user, enterprise)

payload = { "user": user,
"name": name,
"description": description,
"homepage": homepage,
"private": private,
"has_issues": has_issues,
"has_projects": has_projects,
"has_wiki": has_wiki,
"team_id": team_id,
"auto_init": auto_init,
"gitignore_template": gitignore_template,
"license_template": license_template,
"allow_squash_merge": allow_squash_merge,
"allow_merge_commit": allow_merge_commit,
"allow_rebase_merge": allow_rebase_merge,
"allow_auto_merge": allow_auto_merge,
"delete_branch_on_merge": delete_branch_on_merge,
"has_downloads": has_downloads,
"is_template": is_template}

response = self._request("POST",
"/user/repos",
payload,
self.token,
enterprise)

results = {'owner': response['owner']['login']}
results['response'] = response

return results
83 changes: 83 additions & 0 deletions actions/create_repository_authenticated_user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
name: create_repository_authenticated_user
runner_type: python-script
pack: github
description: >
Creates a Github repository fot the authenticated user.
Example:
st2 run github.create_repository_authenticated_user user="user" name="reponame" description="test github.create_repository" private=false api_user="token_name"
enabled: true
entry_point: create_repository_authenticated_user.py
parameters:
api_user:
type: "string"
description: "The API user"
default: "{{action_context.api_user|default(None)}}"
user:
type: "string"
description: "GitHub User."
required: true
name:
type: "string"
description: "The name of the repository."
required: true
description:
type: "string"
description: "A short description of the repository."
github_type:
type: "string"
description: "The type of github installation to target, if unset will use the configured default."
enum:
- "online"
- "enterprise"
default: "online"
homepage:
type: "string"
description: "A URL with more information about the repository."
private:
type: "boolean"
description: "Whether the repository is private."
default: true
has_issues:
type: "boolean"
description: "Whether issues are enabled."
has_projects:
type: "boolean"
description: "Whether projects are enabled."
has_wiki:
type: "boolean"
description: "Whether the wiki is enabled."
team_id:
type: "integer"
description: "The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization."
auto_init:
type: "boolean"
description: "Whether the repository is initialized with a minimal README."
gitignore_template:
type: "string"
description: "The desired language or platform to apply to the .gitignore."
license_template:
type: "string"
description: "The license keyword of the open source license for this repository."
allow_squash_merge:
type: "boolean"
description: "Whether to allow squash merges for pull requests."
allow_merge_commit:
type: "boolean"
description: "Whether to allow merge commits for pull requests."
allow_rebase_merge:
type: "boolean"
description: "Whether to allow rebase merges for pull requests."
allow_auto_merge:
type: "boolean"
description: "Whether to allow Auto-merge to be used on pull requests."
delete_branch_on_merge:
type: "boolean"
description: "Whether to delete head branches when pull requests are merged"
has_downloads:
type: "boolean"
description: "Whether downloads are enabled."
is_template:
type: "boolean"
description: "Whether this repository acts as a template that can be used to generate new repositories."
default: false
35 changes: 35 additions & 0 deletions actions/create_repository_from_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
import datetime


from lib.base import BaseGithubAction

__all__ = [
'CreateRepositoryFromTemplateAction'
]

class CreateRepositoryFromTemplateAction(BaseGithubAction):
def run(self, api_user, github_type, template_owner,template_repo,
owner, name, description, include_all_branches, private):

enterprise = self._is_enterprise(github_type)

if api_user:
self.token = self._get_user_token(api_user, enterprise)

payload = { "owner": owner,
"name": name,
"description": description,
"include_all_branches": include_all_branches,
"private": private}

response = self._request("POST",
"/repos/{}/{}/generate".format(template_owner, template_repo),
payload,
self.token,
enterprise)

results = {'owner': response['owner']['login']}
results['response'] = response

return results
47 changes: 47 additions & 0 deletions actions/create_repository_from_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: create_repository_from_template
runner_type: python-script
pack: github
description: >
Creates a Github repository fot an organization.
Example:
st2 run github.create_repository_from_template owner="organization" name="reponame" description="test github.create_repository" private=true template_owner="gittemplate" template_repo="gitrepo" api_user="token_name"
enabled: true
entry_point: create_repository_from_template.py
parameters:
api_user:
type: "string"
description: "The API user"
default: "{{action_context.api_user|default(None)}}"
github_type:
type: "string"
description: "The type of github installation to target, if unset will use the configured default."
enum:
- "online"
- "enterprise"
default: "enterprise"
template_owner:
type: "string"
description: "The template owner."
template_repo:
type: "string"
description: "The template repository."
owner:
type: "string"
description: "The organization or person who will own the new repository. To create a new repository in an organization, the authenticated user must be a member of the specified organization."
required: true
name:
type: "string"
description: "The name of the repository."
required: true
description:
type: "string"
description: "A short description of the repository."
include_all_branches:
type: "boolean"
description: "Set to true to include the directory structure and files from all branches in the template repository, and not just the default branch. Default: false."
default: false
private:
type: "boolean"
description: "Either true to create a new private repository or false to create a new public one."
default: true