Skip to content

Commit df509a2

Browse files
authored
Merge pull request StackStorm-Exchange#6 from MarlonHeiber/fix/add-missing-action
adding missing actions :)
2 parents 26fa095 + a9410ee commit df509a2

6 files changed

+352
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import time
2+
import datetime
3+
4+
5+
from lib.base import BaseGithubAction
6+
7+
__all__ = [
8+
'CreateOrganizationRepositoryAction'
9+
]
10+
11+
12+
class CreateOrganizationRepositoryAction(BaseGithubAction):
13+
def run(self, api_user, org, name, description, github_type, homepage, private, visibility,
14+
has_issues, has_projects, has_wiki, is_template, team_id, auto_init,
15+
gitignore_template, license_template, allow_squash_merge, allow_merge_commit,
16+
allow_rebase_merge, allow_auto_merge, delete_branch_on_merge):
17+
18+
enterprise = self._is_enterprise(github_type)
19+
20+
if api_user:
21+
self.token = self._get_user_token(api_user, enterprise)
22+
23+
payload = {"name": name,
24+
"description": description,
25+
"homepage": homepage,
26+
"private": private,
27+
"visibility": visibility,
28+
"has_issues": has_issues,
29+
"has_projects": has_projects,
30+
"has_wiki": has_wiki,
31+
"is_template": is_template,
32+
"team_id": team_id,
33+
"auto_init": auto_init,
34+
"gitignore_template": gitignore_template,
35+
"license_template": license_template,
36+
"allow_squash_merge": allow_squash_merge,
37+
"allow_merge_commit": allow_merge_commit,
38+
"allow_rebase_merge": allow_rebase_merge,
39+
"allow_auto_merge": allow_auto_merge,
40+
"delete_branch_on_merge": delete_branch_on_merge}
41+
42+
response = self._request("POST",
43+
"/orgs/{}/repos".format(org),
44+
payload,
45+
self.token,
46+
enterprise)
47+
48+
results = {'owner': response['owner']['login']}
49+
results['response'] = response
50+
51+
return results
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
name: create_organization_repository
3+
runner_type: python-script
4+
pack: github
5+
description: >
6+
Creates a Github repository fot an organization.
7+
Example:
8+
st2 run github.create_organization_repository org="organization" name="reponame" description="test github.create_repository" private=true visibility="private" api_user="token_name"
9+
enabled: true
10+
entry_point: create_organization_repository.py
11+
parameters:
12+
api_user:
13+
type: "string"
14+
description: "The API user"
15+
default: "{{action_context.api_user|default(None)}}"
16+
org:
17+
type: "string"
18+
description: "GitHub Organization."
19+
required: true
20+
name:
21+
type: "string"
22+
description: "The name of the repository."
23+
required: true
24+
description:
25+
type: "string"
26+
description: "A short description of the repository."
27+
github_type:
28+
type: "string"
29+
description: "The type of github installation to target, if unset will use the configured default."
30+
enum:
31+
- "online"
32+
- "enterprise"
33+
default: "enterprise"
34+
homepage:
35+
type: "string"
36+
description: "A URL with more information about the repository."
37+
private:
38+
type: "boolean"
39+
description: "Whether the repository is private."
40+
default: true
41+
visibility:
42+
type: "string"
43+
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."
44+
enum:
45+
- "private"
46+
- "public"
47+
- "internal"
48+
default: "private"
49+
has_issues:
50+
type: "boolean"
51+
description: "Whether issues are enabled."
52+
has_projects:
53+
type: "boolean"
54+
description: "Whether projects are enabled."
55+
has_wiki:
56+
type: "boolean"
57+
description: "Whether the wiki is enabled."
58+
is_template:
59+
type: "boolean"
60+
description: "Whether this repository acts as a template that can be used to generate new repositories."
61+
default: false
62+
team_id:
63+
type: "integer"
64+
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."
65+
auto_init:
66+
type: "boolean"
67+
description: "Whether the repository is initialized with a minimal README."
68+
gitignore_template:
69+
type: "string"
70+
description: "The desired language or platform to apply to the .gitignore."
71+
license_template:
72+
type: "string"
73+
description: "The license keyword of the open source license for this repository."
74+
allow_squash_merge:
75+
type: "boolean"
76+
description: "Whether to allow squash merges for pull requests."
77+
allow_merge_commit:
78+
type: "boolean"
79+
description: "Whether to allow merge commits for pull requests."
80+
allow_rebase_merge:
81+
type: "boolean"
82+
description: "Whether to allow rebase merges for pull requests."
83+
allow_auto_merge:
84+
type: "boolean"
85+
description: "Whether to allow Auto-merge to be used on pull requests."
86+
delete_branch_on_merge:
87+
type: "boolean"
88+
description: "Whether to delete head branches when pull requests are merged"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
from lib.base import BaseGithubAction
3+
4+
__all__ = [
5+
'CreateRepositoryAuthenticatedUserAction'
6+
]
7+
8+
class CreateRepositoryAuthenticatedUserAction(BaseGithubAction):
9+
def run(self, api_user, user, name, description, github_type, homepage, private,
10+
has_issues, has_projects, has_wiki, team_id, auto_init, gitignore_template,
11+
license_template, allow_squash_merge, allow_merge_commit, allow_rebase_merge,
12+
allow_auto_merge, delete_branch_on_merge, has_downloads, is_template, ):
13+
14+
enterprise = self._is_enterprise(github_type)
15+
16+
if api_user:
17+
self.token = self._get_user_token(api_user, enterprise)
18+
19+
payload = { "user": user,
20+
"name": name,
21+
"description": description,
22+
"homepage": homepage,
23+
"private": private,
24+
"has_issues": has_issues,
25+
"has_projects": has_projects,
26+
"has_wiki": has_wiki,
27+
"team_id": team_id,
28+
"auto_init": auto_init,
29+
"gitignore_template": gitignore_template,
30+
"license_template": license_template,
31+
"allow_squash_merge": allow_squash_merge,
32+
"allow_merge_commit": allow_merge_commit,
33+
"allow_rebase_merge": allow_rebase_merge,
34+
"allow_auto_merge": allow_auto_merge,
35+
"delete_branch_on_merge": delete_branch_on_merge,
36+
"has_downloads": has_downloads,
37+
"is_template": is_template}
38+
39+
response = self._request("POST",
40+
"/user/repos",
41+
payload,
42+
self.token,
43+
enterprise)
44+
45+
results = {'owner': response['owner']['login']}
46+
results['response'] = response
47+
48+
return results
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: create_repository_authenticated_user
3+
runner_type: python-script
4+
pack: github
5+
description: >
6+
Creates a Github repository fot the authenticated user.
7+
Example:
8+
st2 run github.create_repository_authenticated_user user="user" name="reponame" description="test github.create_repository" private=false api_user="token_name"
9+
enabled: true
10+
entry_point: create_repository_authenticated_user.py
11+
parameters:
12+
api_user:
13+
type: "string"
14+
description: "The API user"
15+
default: "{{action_context.api_user|default(None)}}"
16+
user:
17+
type: "string"
18+
description: "GitHub User."
19+
required: true
20+
name:
21+
type: "string"
22+
description: "The name of the repository."
23+
required: true
24+
description:
25+
type: "string"
26+
description: "A short description of the repository."
27+
github_type:
28+
type: "string"
29+
description: "The type of github installation to target, if unset will use the configured default."
30+
enum:
31+
- "online"
32+
- "enterprise"
33+
default: "online"
34+
homepage:
35+
type: "string"
36+
description: "A URL with more information about the repository."
37+
private:
38+
type: "boolean"
39+
description: "Whether the repository is private."
40+
default: true
41+
has_issues:
42+
type: "boolean"
43+
description: "Whether issues are enabled."
44+
has_projects:
45+
type: "boolean"
46+
description: "Whether projects are enabled."
47+
has_wiki:
48+
type: "boolean"
49+
description: "Whether the wiki is enabled."
50+
team_id:
51+
type: "integer"
52+
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."
53+
auto_init:
54+
type: "boolean"
55+
description: "Whether the repository is initialized with a minimal README."
56+
gitignore_template:
57+
type: "string"
58+
description: "The desired language or platform to apply to the .gitignore."
59+
license_template:
60+
type: "string"
61+
description: "The license keyword of the open source license for this repository."
62+
allow_squash_merge:
63+
type: "boolean"
64+
description: "Whether to allow squash merges for pull requests."
65+
allow_merge_commit:
66+
type: "boolean"
67+
description: "Whether to allow merge commits for pull requests."
68+
allow_rebase_merge:
69+
type: "boolean"
70+
description: "Whether to allow rebase merges for pull requests."
71+
allow_auto_merge:
72+
type: "boolean"
73+
description: "Whether to allow Auto-merge to be used on pull requests."
74+
delete_branch_on_merge:
75+
type: "boolean"
76+
description: "Whether to delete head branches when pull requests are merged"
77+
has_downloads:
78+
type: "boolean"
79+
description: "Whether downloads are enabled."
80+
is_template:
81+
type: "boolean"
82+
description: "Whether this repository acts as a template that can be used to generate new repositories."
83+
default: false
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import time
2+
import datetime
3+
4+
5+
from lib.base import BaseGithubAction
6+
7+
__all__ = [
8+
'CreateRepositoryFromTemplateAction'
9+
]
10+
11+
class CreateRepositoryFromTemplateAction(BaseGithubAction):
12+
def run(self, api_user, github_type, template_owner,template_repo,
13+
owner, name, description, include_all_branches, private):
14+
15+
enterprise = self._is_enterprise(github_type)
16+
17+
if api_user:
18+
self.token = self._get_user_token(api_user, enterprise)
19+
20+
payload = { "owner": owner,
21+
"name": name,
22+
"description": description,
23+
"include_all_branches": include_all_branches,
24+
"private": private}
25+
26+
response = self._request("POST",
27+
"/repos/{}/{}/generate".format(template_owner, template_repo),
28+
payload,
29+
self.token,
30+
enterprise)
31+
32+
results = {'owner': response['owner']['login']}
33+
results['response'] = response
34+
35+
return results
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: create_repository_from_template
3+
runner_type: python-script
4+
pack: github
5+
description: >
6+
Creates a Github repository fot an organization.
7+
Example:
8+
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"
9+
enabled: true
10+
entry_point: create_repository_from_template.py
11+
parameters:
12+
api_user:
13+
type: "string"
14+
description: "The API user"
15+
default: "{{action_context.api_user|default(None)}}"
16+
github_type:
17+
type: "string"
18+
description: "The type of github installation to target, if unset will use the configured default."
19+
enum:
20+
- "online"
21+
- "enterprise"
22+
default: "enterprise"
23+
template_owner:
24+
type: "string"
25+
description: "The template owner."
26+
template_repo:
27+
type: "string"
28+
description: "The template repository."
29+
owner:
30+
type: "string"
31+
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."
32+
required: true
33+
name:
34+
type: "string"
35+
description: "The name of the repository."
36+
required: true
37+
description:
38+
type: "string"
39+
description: "A short description of the repository."
40+
include_all_branches:
41+
type: "boolean"
42+
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."
43+
default: false
44+
private:
45+
type: "boolean"
46+
description: "Either true to create a new private repository or false to create a new public one."
47+
default: true

0 commit comments

Comments
 (0)