Skip to content

Commit 5feba1c

Browse files
author
Jon Lockwood
committed
Merge pull request 'fix: No problems found' (#6) from fix-5-no-promlems-approve-pr into development
Reviewed-on: https://nofusscomputing.com/git/ansible-collections/git-events/pulls/6
2 parents 6d501e2 + e03a201 commit 5feba1c

File tree

7 files changed

+162
-46
lines changed

7 files changed

+162
-46
lines changed

.cz.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ commitizen:
1212
- fix
1313
- test
1414
- refactor
15+
# yamllint disable rule:line-length
1516
commit_parser: ^(?P<change_type>feat|fix|test|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?
17+
# yamllint enable rule:line-length
1618
name: cz_customize
1719
prerelease_offset: 1
1820
tag_format: $version

.gitea/workflows/pull_request.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
3+
name: Lint (Pull Request)
4+
5+
6+
on:
7+
pull_request: {}
8+
9+
10+
jobs:
11+
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
17+
- name: Enable Matcher Service
18+
run: |
19+
echo "NFC_PROBLEM_MATCHER=${GITHUB_REF_NAME}";
20+
21+
22+
- uses: actions/checkout@v3
23+
24+
25+
- name: Install YAMLLint
26+
run: pip install yamllint
27+
28+
29+
- name: Run YAMLLint
30+
run: |
31+
echo "NFC_PROBLEM_MATCHER_TYPE=YAML-Lint"
32+
yamllint -f github . || true
33+
34+
35+
- name: Install Ansible-Lint
36+
run: pip install ansible-lint
37+
38+
39+
- name: Run Ansible-Lint
40+
run: |
41+
echo "NFC_PROBLEM_MATCHER_TYPE=pylint-json";
42+
ansible-lint -f json . || true

.yamllint

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
3+
# extends: default
4+
5+
6+
ignore:
7+
- '.github/'
8+
- '**/crd/**'
9+
- mkdocs.yml
10+
- '*PrometheusRule*'
11+
- '**/source/**'
12+
13+
rules:
14+
braces:
15+
level: error
16+
max-spaces-inside: 1
17+
min-spaces-inside: 1
18+
min-spaces-inside-empty: 0
19+
max-spaces-inside-empty: 0
20+
21+
brackets:
22+
level: error
23+
max-spaces-inside: 1
24+
min-spaces-inside: 1
25+
min-spaces-inside-empty: 0
26+
max-spaces-inside-empty: 0
27+
28+
colons:
29+
level: warning
30+
max-spaces-after: 1
31+
32+
commas:
33+
level: warning
34+
35+
comments:
36+
level: error
37+
require-starting-space: true
38+
ignore-shebangs: true
39+
min-spaces-from-content: 4
40+
41+
comments-indentation:
42+
level: error
43+
44+
document-end:
45+
level: error
46+
present: false
47+
48+
document-start:
49+
level: error
50+
present: true
51+
52+
empty-lines:
53+
level: error
54+
max: 3
55+
max-start: 0
56+
max-end: 0
57+
58+
hyphens:
59+
level: error
60+
max-spaces-after: 1
61+
62+
indentation:
63+
level: error
64+
spaces: 2
65+
indent-sequences: true
66+
check-multi-line-strings: true
67+
68+
line-length:
69+
level: warning
70+
max: 100
71+
allow-non-breakable-inline-mappings: true
72+
73+
new-lines:
74+
level: error
75+
type: unix
76+
77+
truthy: disable

extensions/eda/rulebooks/problem_matcher.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
2828
2929
- name: Process Completed workflow_job
30+
# yamllint disable rule:indentation
3031
condition: >
3132
event.meta.headers['X-GitHub-Event'] == 'workflow_job'
3233
and
3334
event.payload.action == 'completed'
35+
# yamllint enable rule:indentation
3436
actions:
3537

3638
- run_playbook:

galaxy.yml

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,46 @@
11
---
22

3-
### REQUIRED
4-
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
5-
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
6-
# underscores or numbers and cannot contain consecutive underscores
73
namespace: nofusscomputing
84

9-
# The name of the collection. Has the same character restrictions as 'namespace'
105
name: git_events
116

12-
# The version of the collection. Must be compatible with semantic versioning
137
version: 0.0.1
148

15-
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
169
readme: README.md
1710

18-
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
19-
# @nicks:irc/im.site#channel'
2011
authors:
2112
- No Fuss Computing
2213

23-
### OPTIONAL but strongly recommended
24-
# A short summary description of the collection
2514
description: Git[ea/hub] Problem matcher parser with PR Code Review
26-
27-
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
28-
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
2915
license:
3016
- MIT
3117

32-
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
33-
# mutually exclusive with 'license'
3418
license_file: LICENCE
3519

36-
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
37-
# requirements as 'namespace' and 'name'
3820
tags:
3921
- ci
4022
- event
4123
- rulebook
4224
- tools
4325

44-
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
45-
# collection label 'namespace.name'. The value is a version range
46-
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
47-
# range specifiers can be set and are separated by ','
4826
dependencies: {}
4927

50-
# The URL of the originating SCM repository
5128
repository: https://nofusscomputing.com/git/ansible-collections/git-events
5229

53-
# The URL to any online docs
5430
documentation: https://nofusscomputing.com/git/ansible-collections/git-events
5531

56-
# The URL to the homepage of the collection/project
5732
homepage: https://nofusscomputing.com/git/ansible-collections/git-events
5833

59-
# The URL to the collection issue tracker
6034
issues: https://nofusscomputing.com/git/ansible-collections/git-events/issues
6135

62-
# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
63-
# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This
64-
# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry',
65-
# and '.git' are always filtered. Mutually exclusive with 'manifest'
6636
build_ignore: [
6737
'.ansible',
6838
artifacts/,
39+
'.cz.yaml',
40+
'.dockerignore',
41+
'dockerfile',
6942
'.git',
7043
'galaxy.yml',
7144
'*.tmp.*'
7245

7346
]
74-
# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a
75-
# list of MANIFEST.in style
76-
# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key
77-
# 'omit_default_directives' is a boolean that controls whether the default directives are used. Mutually exclusive
78-
# with 'build_ignore'
79-
# manifest: null

includes/usr/bin/annotations.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# import requests
77
import os
88

9-
9+
# API Docs: https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request
1010

1111
def default_matcher( entry, tool_name = '' ) -> dict:
1212

@@ -144,8 +144,8 @@ def pylint_matcher( entry ) -> dict:
144144
r'"description":\s*"(?P<description>[^"]+)",\s*'
145145
r'"fingerprint":\s*"(?P<fingerprint>[^"]+)",\s*'
146146
r'"location":\s*\{\s*"path":\s*"(?P<path>[^"]+)".+?'
147-
r'"line[s]?":.+?(?P<line>\d+).*?\}},'
148-
r'(?:\s"content":\s\{"body":\s"(?P<body>.+?)")?'
147+
r'"line[s]?":.+?(?P<line>\d+).*?\}}'
148+
r'(?:,\s"content":\s\{"body":\s"(?P<body>.+?)")?'
149149
)
150150
}
151151

@@ -205,7 +205,11 @@ def pylint_matcher( entry ) -> dict:
205205

206206
if not NFC_PROBLEM_MATCHER:
207207

208-
sys.exit(2)
208+
print(json.dumps({
209+
'pull_request': ''
210+
}, indent=4))
211+
212+
sys.exit(0)
209213

210214

211215
if not results:
@@ -277,6 +281,14 @@ def pylint_matcher( entry ) -> dict:
277281
)
278282

279283

284+
if len(api_body['comments']) == 0:
285+
286+
api_body.update({
287+
'body': "G'day, I didn't find any problems to report on",
288+
'event': 'APPROVE'
289+
})
290+
291+
280292
data = {
281293
"pull_request": pull_request,
282294
"api_body": api_body

playbooks/problem_matcher.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@
1818
ansible.builtin.set_fact:
1919
git_api_url: "{{ payload.repository.url }}"
2020
when: >
21-
git_api_url == ""
21+
git_api_url == ""
2222
2323
2424
- name: Set var gitea_replace_url if empty
2525
ansible.builtin.set_fact:
2626
gitea_replace_url: "{{ payload.repository.url }}"
2727
when: >
28-
gitea_replace_url == ""
28+
gitea_replace_url == ""
2929
3030
3131
- name: Set required Facts
3232
ansible.builtin.set_fact:
33-
git_url_api: "{{ payload.repository.url | replace((gitea_replace_url | split('/api/'))[0], git_api_url) }}"
33+
git_url_api: >-
34+
{{ payload.repository.url |
35+
replace((gitea_replace_url | split('/api/'))[0], git_api_url) }}
3436
git_url_path_jobs: 'actions/jobs'
3537
head_sha: "{{ payload.workflow_job.head_sha }}"
3638

@@ -51,7 +53,9 @@
5153

5254
- name: Fetch job log
5355
ansible.builtin.uri:
54-
url: "{{ git_url_api + '/' + git_url_path_jobs + '/' + payload.workflow_job.id | string + '/logs' }}"
56+
url: >-
57+
{{ git_url_api + '/' + git_url_path_jobs
58+
+ '/' + payload.workflow_job.id | string + '/logs' }}
5559
dest: /tmp/job.log
5660
headers:
5761
Authorization: token {{ lookup('env', 'GIT_API_TOKEN') }}
@@ -67,7 +71,9 @@
6771
cmd: |
6872
set -o pipefail;
6973
70-
export GITHUB_ACTOR={{ payload.sender.username }}
74+
export GITHUB_ACTOR={{ payload.sender.username }};
75+
76+
export GITHUB_SHA={{ payload.workflow_job.head_sha }};
7177
7278
cat /tmp/job.log | annotations > /tmp/annotations.json;
7379
@@ -94,11 +100,15 @@
94100
validate_certs: false
95101
no_log: "{{ disable_logging }}"
96102
register: http_get_pull_request
103+
when: >
104+
annotations.pull_request | string
97105
98106
99107
- name: Trace - Display Pull Request State
100108
ansible.builtin.debug:
101109
msg: "{{ http_get_pull_request.json.state | default('No PR found') }}"
110+
when: >
111+
not http_get_pull_request.skipped | default(false) | bool
102112
103113
104114
- name: Post review
@@ -113,7 +123,11 @@
113123
timeout: 10
114124
validate_certs: false
115125
no_log: "{{ disable_logging }}"
126+
# yamllint disable rule:indentation
116127
when: >
117128
http_get_pull_request.json.state | default('-') != 'closed'
118129
and
119-
http_get_pull_request.status == 200
130+
http_get_pull_request.status | default(0) == 200
131+
and
132+
not http_get_pull_request.skipped | default(false) | bool
133+
# yamllint enable rule:indentation

0 commit comments

Comments
 (0)