lib/lita/handlers/github_repo.rb in lita-github-0.2.2 vs lib/lita/handlers/github_repo.rb in lita-github-0.3.0
- old
+ new
@@ -40,14 +40,15 @@
route(
/#{LitaGithub::R::A_REG}repo\s+?(?:create|new)\s+?#{LitaGithub::R::REPO_REGEX}.*$/,
:repo_create,
command: true,
help: {
- 'gh repo create PagerDuty/lita-github private:true team:heckman' =>
- 'Create the PagerDuty/lita-github repo, make it private, use team with "heckman" slug',
+ 'gh repo create PagerDuty/lita-github private:true team:heckman admin:anon' =>
+ 'Create the PagerDuty/lita-github repo, make it private,'\
+ 'use team with "heckman" slug, with GitHub user "anon" as repo admin',
'gh repo new PagerDuty/lita-github' =>
- 'create new repo using the default privacy/team settings'
+ 'create new repo using the default privacy, team, admin settings'
}
)
route(
/#{LitaGithub::R::A_REG}repo\s+?delete\s+?#{LitaGithub::R::REPO_REGEX}/,
@@ -331,10 +332,11 @@
begin
octo.create_repository(repo, opts)
opts[:other_teams].each do |team_id|
add_team_to_repo(full_name, gh_team(org, team_id))
end if opts.key?(:other_teams)
+ add_admin_to_repo(full_name, opts[:admin]) if opts.key?(:admin)
ensure
if repo?(full_name)
repo_url = "https://github.com/#{full_name}"
reply = t('repo_create.pass', org: org, repo: repo, repo_url: repo_url)
else
@@ -397,9 +399,17 @@
def remove_team_from_repo(full_name, team)
if octo.remove_team_repository(team[:id], full_name)
return t('repo_team_rm.pass', repo: full_name, team: team[:name])
else
return t('repo_team_rm.fail', repo: full_name, team: team[:name])
+ end
+ end
+
+ def add_admin_to_repo(full_name, user)
+ if octo.add_collaborator(full_name, user, permission: 'admin')
+ return t('repo_admin_add.pass', repo: full_name, user: user)
+ else
+ return t('repo_admin_add.fail', repo: full_name, user: user)
end
end
end
Lita.register_handler(GithubRepo)