-
Notifications
You must be signed in to change notification settings - Fork 71
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea.
moduleroot/.github/settings.yml
Outdated
required_status_checks: | ||
strict: true | ||
contexts: ['continuous-integration/travis-ci'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't work for our release workflow. Also not sure if there might be a difference between legacy open source Travis and the modern one. Might be that we have some modules using the modern one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bastelfreak mentioned that the travis_relase
task might fail, but we could set enforce_admins: null
to override this behavior.
I do not know, if we are able to check the current Travis CI version, but it should be possible to configure multiple contexts like Travis CI and Jenkins. In the end it is an array, but I have to take a look at the docs, if this will be treated as and
condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I know this will break our release process (that's why I tested this long time ago and had to remove the branch protection again). This will enforce that travis runs for every PR and only PRs are allowed for the protected branch. You cannot push anymore directly to master. This in general should be our goal, but our travis_release task directly pushes to master:
https://github.com/voxpupuli/voxpupuli-release-gem/blob/fb73087fda1f64b79ee3bb668e3a4ce6cd8626b1/lib/voxpupuli/release/rake_tasks.rb#L32-L33
If I remember corretly nobody can push to master, even admins. admins "only" have the power to merge PRs if travis is still running/failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bastelfreak I think you have missed my comment regarding enforce_admins: null
.
I was able to merge a pull request, although the conditions for the Travis CI check were not fulfilled:
I also was able to push to the master branch:
This might be related to the CODEOWNERS
.
I think it would be best if I make a template from the files and we start with some small changes in the config_defaults.yml
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be tested by Travis, but Travis/Github identifies by commit. That means you can push it to a branch, get it tested and merged. Perhaps you can change the script to push to a next-release
branch and set up auto merge rules for that with something like mergify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the required_pull_request_reviews
, required_status_checks
, enforce_admins
and restrictions
to get started.
Thanks for the tip on mergify
. I will ll take a look at it later.
moduleroot/.github/settings.yml
Outdated
has_projects: false | ||
has_wiki: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, but have we checked whether this is actually true? Or do you want to do that as part of the modulesync review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to loop over managed_modules.yml
to fetch the current values regarding projects
and wiki
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many repositories use projects
and / or wiki
because this is a default value during the creation process. I think we need to check this manually during the modulesync
and modify it if necessary via .sync.yml
.
One thing to consider is that there are people who use our modulesync on their own modules. On the other hand, they can delete the file if they want to. |
We should add a section to the |
moduleroot/.github/settings.yml.erb
Outdated
<% end -%> | ||
<% if @configs['branches'] -%> | ||
|
||
branches: |
There was a problem hiding this comment.
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.
moduleroot/.github/settings.yml.erb
Outdated
branches: | ||
<% @configs['branches'].each do |branch| -%> | ||
- name: <%= branch['name'] %> | ||
<% branch.keys.each do |k| -%> |
There was a problem hiding this comment.
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
<% branch.keys.each do |k| -%> | |
<% branch.keys.each do |key, value| -%> |
This avoids the whole branch[k]
part.
moduleroot/.github/settings.yml.erb
Outdated
<% if branch[k].has_key?('required_pull_request_reviews') -%> | ||
<% if branch[k]['required_pull_request_reviews'].nil? -%> |
There was a problem hiding this comment.
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.
moduleroot/.github/settings.yml.erb
Outdated
- name: <%= label['name'] %> | ||
<% label.keys.each do |k| -%> | ||
<% next if k == 'name' -%> | ||
<%= k %>: <%= label[k] %> | ||
<% end -%> | ||
<% end -%> |
There was a problem hiding this comment.
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:
- 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 -%> |
moduleroot/.github/settings.yml.erb
Outdated
@@ -0,0 +1,52 @@ | |||
<% if @configs['repository'] -%> |
There was a problem hiding this comment.
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 %>
There was a problem hiding this comment.
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
.
…checks, enforce_admins and restrictions
moduleroot/CODEOWNERS.erb
Outdated
<% if @configs['permissions'] -%> | ||
<% @configs['permissions'].each do |key, value| -%> | ||
<%= key %> <%= value %> | ||
<% end -%> | ||
<% end -%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested, but I think this will result in the same:
<% if @configs['permissions'] -%> | |
<% @configs['permissions'].each do |key, value| -%> | |
<%= key %> <%= value %> | |
<% end -%> | |
<% end -%> | |
<% @configs['permissions']&.each do |key, value| -%> | |
<%= key %> <%= value %> | |
<% end -%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does. Honestly, how many Ruby books do you have hidden under your pillow? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None, I still consider myself a novice Ruby developer tbh. Just look at a bunch of other devs and PR reviews. Copy that. That's how I learned the language constructs. This one is called the safe navigation operator and was introduced in Ruby 2.3.
Also read the core data structures (Array, Hash, String and Integer) when you deal with them. The list of methods is useful.
Once you have a decent understanding of what's possible, you can express yourself much more powerful.
I think now we have a working version that we could test on a repository. This should cover most of the features of voxpupuli/vox-pupuli-tasks#14 |
config_defaults.yml
Outdated
CODEOWNERS: | ||
permissions: | ||
'.github/settings.yml': '@voxpupuli/project-maintainers' | ||
'*': '@voxpupuli/collaborators' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will send an email to every collaborator, right? Is that maybe too noisy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now I purposely unwatched a lot of repositories precisely because of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn. This was supposed to be a failsafe, according to the docs of Probot. I will drop the last line, but the first one is necessary:
I think I understand the problem now. GitHub allows things on its website that do not work with Curl or Probot. I actually think it is quite nice when a review of the pull request is needed. However, this does not work with the task However, I will still contact GitHub support to have branches automatically deleted after a merge and to create protection rules for non-existent branches. |
…by Probot and will even untick this setting
has_projects: false | ||
has_wiki: false | ||
has_downloads: true | ||
default_branch: master |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
This pull request allows us to manage the GitHub settings via Probot. I left out the labels, as they are managed by
vox-pupuli-tasks
.Maybe we can also read the file
metadata.json
to automatically add values forname
,description
,homepage
andtopics
.Unfortunately, the
delete_merge_on_branch
parameter does not work yet:Also, the rule for the
modulesync
branch will not be applied if it does not already exist: