Skip to content

Commit

Permalink
Merge pull request #313 from voxpupuli/add-support-for-vpt-in-sync
Browse files Browse the repository at this point in the history
Add support for vpt in sync
  • Loading branch information
Flipez authored Aug 29, 2021
2 parents fba8736 + d96cfce commit 1d4dc9e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [Existing Automatisation](#existing-automatisation)
- [Merge Conflicts - Milestone 1](#merge-conflicts---milestone-1)
- [Sync GitHub Labels](#sync-github-labels)
- [Configure your module repo](#configure-your-module-repo)
- [Local Setup](#local-setup)
- [Dry Run](#dry-run)
- [Production Setup](#production-setup)
Expand Down Expand Up @@ -183,6 +184,23 @@ renamed to the correct one.

The work for this feature is/was tracked in [issue #131](https://github.com/voxpupuli/vox-pupuli-tasks/issues/131).

## Configure your module repo
> The old list with repos to ignore is still active but will be replaced with the below workflow soon.
Per default VPT does take care of every repo in the voxpupuli group matching `/^puppet-(?!lint)/`.

You can configure VPT on a repository level to override some of the default behavior via the `.sync.yml` file.

Example configuration of the current posibilities:

```yml
vpt:
enabled: false # vpt will ignore this repository completely if false. default: true
comment_on:
needs_rebase: false # vpt will post a comment if a pull request gets conflicts with the target branch if true, default: true
tests_failed: false # vpt will post a comment if the ci tests enter a failed state if true, default: true
```
## Local Setup
To start the app locally, do the following (assumes that you've ruby, bundler
Expand Down
2 changes: 2 additions & 0 deletions app/models/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def ensure_label_is_detached(label)
# Only attach a comment if eligible_for_merge_comment is true (The first iteration
# after the mergeable state changed to false)
def add_merge_comment
return if repository.vpt_config.dig('comment_on', 'needs_rebase') == false
return unless eligible_for_merge_comment

add_comment(I18n.t('comment.needs_rebase', author: author))
Expand All @@ -138,6 +139,7 @@ def add_merge_comment
# This logic is required to prevent comments for failure -> pending -> failure
# Also it prevents duplicate comments
def add_ci_comment
return if repository.vpt_config.dig('comment_on', 'tests_failed') == false
return unless eligible_for_ci_comment

add_comment(I18n.t('comment.tests_fail', author: author))
Expand Down
23 changes: 23 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class Repository < ApplicationRecord

##
# Checks if the given Repository name is in our application scope (a module)
#
# The config can be a hash containing a 'enabled' key.
# Only if the key explicitly contains false we skip right away, a missing key does default to true.
def notably?
return false if vpt_config['enabled'] == false

Repository.notably?(name)
end

def self.notably?(name)
/^puppet-(?!lint)/.match?(name) && LEGACY_OR_BROKEN_NOBODY_KNOWS.exclude?(name)
Expand Down Expand Up @@ -175,6 +183,21 @@ def update_pull_requests(only_open: false)
pull_requests.count
end

##
# Within the .sync.yml you can optionally place some vpt config
# If there is some content, we set this in the repo to avoid multiple github requests
# If the file is missing completely, we also remove the config locally.
def update_vpt_config
sync_file = Github.get_file(full_name, '.sync.yml')

if sync_file
content = YAML.safe_load(sync_file)
update(vpt_config: content['vpt'].to_h)
elsif vpt_config.any?
update(vpt_config: {})
end
end

def healty?
repository_statuses.last.checks.values.all?
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20210815140513_add_config_to_repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddConfigToRepository < ActiveRecord::Migration[6.1]
def change
add_column :repositories, :vpt_config, :json, default: {}
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_07_23_173538) do
ActiveRecord::Schema.define(version: 2021_08_15_140513) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -66,6 +66,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.json "todos", default: {}
t.json "vpt_config", default: {}
t.index ["github_id"], name: "index_repositories_on_github_id", unique: true
t.index ["name"], name: "index_repositories_on_name", unique: true
end
Expand Down

0 comments on commit 1d4dc9e

Please sign in to comment.