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

Manage GitHub settings via Probot #654

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
35 changes: 35 additions & 0 deletions config_defaults.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
---
.github/settings.yml:
repository:
private: false
has_issues: true
has_projects: false
has_wiki: false
has_downloads: true
default_branch: master
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe out of scope for this specific PR, but has there been discussion of changing the default branch name to main?

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK there has not been any discussion on this.

allow_squash_merge: true
allow_merge_commit: true
allow_rebase_merge: true
delete_branch_on_merge: true
archived: false
branches:
- name: master
protection:
required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: true
require_code_owner_reviews: true
required_status_checks:
strict: true
contexts: ['continuous-integration/travis-ci']
enforce_admins: ~
restrictions: ~
required_signatures: true
- name: modulesync
protection:
required_pull_request_reviews: ~
required_status_checks:
strict: true
contexts: ['continuous-integration/travis-ci']
enforce_admins: ~
restrictions: ~
required_signatures: true
.travis.yml:
before_install:
- yes | gem update --system
Expand Down
52 changes: 52 additions & 0 deletions moduleroot/.github/settings.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<% if @configs['repository'] -%>
Copy link
Member

@ekohl ekohl May 13, 2020

Choose a reason for hiding this comment

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

Another thought for this file:

data = {}
['repository', 'labels', 'branches'].each do |key|
  data[key] = @configs[key] if @configs[key]
end
-%>
<%= data.to_yaml %>

Edit: even shorter:

<%= @configs.slice('repository', 'labels', 'branches').to_yaml %>

Copy link
Member Author

Choose a reason for hiding this comment

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

That is what I was looking for, but it was so late. However ~ is not interpreted as null.

repository:
<% @configs['repository'].each do |key, value| -%>
<%= key %>: <%= value %>
<% end -%>
<% end -%>
<% if @configs['labels'] -%>

labels:
<% @configs['labels'].each do |label| -%>
- name: <%= label['name'] %>
<% label.keys.each do |k| -%>
<% next if k == 'name' -%>
<%= k %>: <%= label[k] %>
<% end -%>
<% end -%>
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if delete is pretty, but I think it works:

Suggested change
- name: <%= label['name'] %>
<% label.keys.each do |k| -%>
<% next if k == 'name' -%>
<%= k %>: <%= label[k] %>
<% end -%>
<% end -%>
- name: <%= label.delete('name') %>
<% label.each do |key, value| -%>
<%= key %>: <%= value %>
<% end -%>
<% end -%>

<% end -%>
<% if @configs['branches'] -%>

branches:
Copy link
Member Author

Choose a reason for hiding this comment

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

I am pretty sure that this can be done easier.

<% @configs['branches'].each do |branch| -%>
- name: <%= branch['name'] %>
<% branch.keys.each do |k| -%>
Copy link
Member

Choose a reason for hiding this comment

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

You can also iterate over the tuples

Suggested change
<% branch.keys.each do |k| -%>
<% branch.keys.each do |key, value| -%>

This avoids the whole branch[k] part.

<% next if k == 'name' -%>
<%= k %>:
<% if branch[k].has_key?('required_pull_request_reviews') -%>
<% if branch[k]['required_pull_request_reviews'].nil? -%>
Copy link
Member

Choose a reason for hiding this comment

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

branch[k]['required_pull_request_reviews'] is nil, whether the key exists or not. It's not like Python which raises an exception if the key is not set.

required_pull_request_reviews: null
<% else -%>
required_pull_request_reviews:
required_approving_review_count: <%= branch[k]['required_pull_request_reviews']['required_approving_review_count'] %>
dismiss_stale_reviews: <%= branch[k]['required_pull_request_reviews']['dismiss_stale_reviews'] %>
require_code_owner_reviews: <%= branch[k]['required_pull_request_reviews']['require_code_owner_reviews'] %>
<% end -%>
<% end -%>
<% if branch[k].has_key?('required_status_checks') -%>
required_status_checks:
strict: <%= branch[k]['required_status_checks']['strict'] %>
contexts: <%= branch[k]['required_status_checks']['contexts'] %>
<% end -%>
<% if branch[k].has_key?('enforce_admins') -%>
enforce_admins: <%= branch[k]['enforce_admins'] || 'null' %>
<% end -%>
<% if branch[k].has_key?('restrictions') -%>
restrictions: <%= branch[k]['restrictions'] || 'null' %>
<% end -%>
<% if branch[k].has_key?('required_signatures') -%>
required_signatures: <%= branch[k]['required_signatures'] %>
<% end -%>
<% end -%>
<% end -%>
<% end -%>
3 changes: 3 additions & 0 deletions moduleroot/CODEOWNERS.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/settings.yml @voxpupuli/project-maintainers

* @voxpupuli/collaborators