Get data from Git commit and put it into a YAML (Gitlab)

as the title says I want to read information of my git commit (user ID, message) and put it into a yaml file, which will be created in my current project folder and push the changes with the yaml file into git. I think I have to work with the GITLAB API but I’m not sure how.

It sounds complicated but the idea is to save yaml files with the information of every commit and these files will be added into a another change list.

This is my code so far, I just implemented the input option, but I want it automatically filled. Does someone know how?

import yaml

data = dict(
    gittag='',
    gittagdate='',
    userID=str(input('autor: ')),
    change_id=str(input('change_id: ')),
    message=str(input('description: ')),

)
with open('test.yml', 'w') as outfile:
    yaml.dump(data, outfile, default_flow_style=False)

You can use environment variables.

Author: no built in variable, you can call git log -1 --pretty=format:'%an'
Commit message: CI_COMMIT_MESSAGE

You’re using Python, so

import os
COMMIT_MESSAGE = os.environ.get('CI_COMMIT_MESSAGE')
print(COMMIT_MESSAGE)