Browse Source

add gitea module and update README

main
Markus Bergholz 6 months ago
parent
commit
092549525d
No known key found for this signature in database
GPG Key ID: B45724801354B174
  1. 42
      README.md
  2. 100
      plugins/modules/gitea_pull_request_comment.py

42
README.md

@ -1,22 +1,27 @@
# Ansible Collection - markuman.scm
# Ansible Collection - markuman.devops
![CI Status](https://woodpecker.aws.osuv.de/api/badges/m/markuman.scm/status.svg)
![CI Status](https://woodpecker.aws.osuv.de/api/badges/ansible_collections/markuman.devops/status.svg)
Documentation for the collection.
`ansible-galaxy collection install markuman.devops`
## markuman.scm.gitlab_merge_request_comment
# markuman.devops
Covers/plan gitlab (_just one_), gitea and woodpecker modules and sentry (_glitchtip_) callback plugin (_so far_).
## markuman.devops.gitlab_merge_request_comment
* Task works only if `CI_OPEN_MERGE_REQUESTS` is defined
* `api_token` parameter can also be read from ENV `ANSIBLE_GITLAB_API_TOKEN`
* It's designed to act like a notification bot for merge requests
* Designed to run in a GitLab CI/CD Pipeline
* Project ID and Merge Request ID are taken from ENV
* On other environments you must possibly fake the requires ENV variables
```yml
- name: post message
markuman.scm.gitlab_merge_request_comment:
markuman.devops.gitlab_merge_request_comment:
api_url: gitlab.com
comment: |
Summary
@ -24,4 +29,29 @@ Documentation for the collection.
| some | table |
| --- | --- |
| yes | 🐧 |
```
```
## markuman.devops.gitea_pull_request_comment
* Tasks works only if `CI_REPO` and `CI_PULL_REQUST` is defined
* `api_token` parameter can also be read from ENV `ANSIBLE_GITEA_API_TOKEN`
* It's designed to act like a notification bot for merge requests
* Designed to run in a Woodpecker CI/CD Pipeline
* On other environments you must possibly fake the requires ENV variables
```yml
- name: post message
markuman.devops.gitea_pull_request_comment:
api_url: git.osuv.de
comment: |
Summary
| some | table |
| --- | --- |
| yes | 🐧 |
```
# Contribute
* Issues and Pull Requests: https://github.com/markuman/markuman.devops
* Origin: https://git.osuv.de/ansible_collections/markuman.devops

100
plugins/modules/gitea_pull_request_comment.py

@ -0,0 +1,100 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: gitea_pull_request_comment
short_description: write messages to gitea pull requests
description:
- write messages to gitea pull requests.
- works only if `CI_PULL_REQUEST` is defined
- it's designed to run inside woodpecker ci/cd pipeline
version_added: "1.0.0"
author:
- "Markus Bergholz (@markuman)"
options:
comment:
description:
- Comment message.
required: true
type: str
api_token:
description:
- API Token.
- If not provided, it's read from ENV ANSIBLE_GITEA_API_TOKEN
required: false
type: str
api_url:
description:
- URL of your gitea instance
required: true
type: str
'''
EXAMPLES = '''
- name: post message
markuman.scm.gitea_pull_request_comment:
api_url: gitea.io
comment: |
Summary
| some | table |
| --- | --- |
| yes | 🐧 |
'''
from ansible.module_utils.basic import AnsibleModule
import requests
import os
def main():
module = AnsibleModule(
argument_spec=dict(
comment=dict(required=True, type='str'),
api_token=dict(required=False, type='str', no_log=True),
api_url=dict(required=True, type='str')
)
)
comment = module.params.get("comment")
api_token = module.params.get("api_token") or os.environ.get('ANSIBLE_GITEA_API_TOKEN')
api_url = module.params.get("api_url")
issue_id = os.environ.get('CI_PULL_REQUEST')
if issue_id and api_token:
repo = os.environ.get('CI_REPO')
gitea_url = f'https://{api_url}/api/v1/repos/{repo}/issues/{issue_id}/comments'
q(gitea_url)
headers = {
'Authorization': f'token {api_token}',
'Content-Type': 'application/json',
'accept': 'application/json'
}
data = {
'body': comment
}
x = requests.post(gitea_url, json = data, headers = headers)
change = False
if x.status_code == 201:
change = True
module.exit_json(changed=change, status=x.status_code)
else:
module.exit_json(changed=False, status=None)
if __name__ == '__main__':
main()
Loading…
Cancel
Save