Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions bin/get_db_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Default values
DB_HOST="localhost"
DB_PORT="5432"

# Check arguments
if [ "$#" -lt 2 ]; then
echo "Usage: $0 DB_NAME DB_USER [DB_HOST] [DB_PORT]"
exit 1
fi

# Assign arguments
DB_NAME="$1"
DB_USER="$2"

# Check if DB_HOST and DB_PORT are provided
if [ ! -z "$3" ]; then
DB_HOST="$3"
fi

if [ ! -z "$4" ]; then
DB_PORT="$4"
fi

# Get the database size
DB_SIZE=$(psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -t -c "SELECT pg_size_pretty(pg_database_size('$DB_NAME'));")

# Echo out the size
echo "Size of $DB_NAME: $DB_SIZE"
84 changes: 84 additions & 0 deletions bin/manage-gitlab-merge-reqs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# pip install requests
# pip install yaml
# pip install ruamel.yaml

import requests
import yaml
from ruamel.yaml import YAML
import argparse


# How to use it:
# python gitlab-script.py glpat-dummyToken789000000 https://gitlab.test.com/api/v4 155 repos.yaml OCA/test


def fetch_and_update_yaml(GITLAB_TOKEN, GITLAB_API_ENDPOINT, PROJECT_IDS,
YAML_FILE, REPO_SECTIONS):
headers = {'Private-Token': GITLAB_TOKEN}
s_yaml = YAML()
# print(f"GITLAB TOKEN: {GITLAB_TOKEN} "
# f"URL ENDPOINT: {GITLAB_API_ENDPOINT} "
# f"PROJECT IDS: {PROJECT_IDS.split(',')} "
# f"REPO SECTIONS: {REPO_SECTIONS.split(',')}")
for PROJECT_ID in PROJECT_IDS.split(','):
# 1. Fetch merged branches using GitLab API
try:
response = requests.get(
f'{GITLAB_API_ENDPOINT}/projects/{PROJECT_ID}/merge_requests?state=merged',
headers=headers)
response.raise_for_status()
except requests.HTTPError as err:
print(f"HTTP error occurred: {err}")
else:
branches_data = response.json()

merged_branches = [b['source_branch'] for b in branches_data]
merged_lst_branches = '\n'.join(merged_branches)
print(f"LIST OF MERGED BRANCHES:\n============================\n"
f" {merged_lst_branches}\n\n")

# 2. Load YAML file
with open(YAML_FILE, 'r') as stream:
# data = yaml.safe_load(stream)
data = s_yaml.load(stream)

for REPO_SECTION in REPO_SECTIONS.split(','):
# 3. Remove merged branches from YAML for each repo section
branches_in_yaml = data[REPO_SECTION]['merges']
found_mr_yaml = ''.join(branches_in_yaml)
print(f'FOUND MERGE REQUESTS ON {YAML_FILE} UNDER '
f'{REPO_SECTION}:'
f'\n===================================================\n'
f' {found_mr_yaml}\n')

for branch in branches_in_yaml.copy():
branch_name = branch.split()[-1]
if branch_name in merged_branches:
print(f"Removing Branch: {branch_name} its already "
f"merged")
branches_in_yaml.remove(branch)

# 4. Save updated YAML
with open(YAML_FILE, 'w') as stream:
s_yaml.dump(data, stream)


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Process branches with GitLab API and update a YAML file.')
parser.add_argument('GITLAB_TOKEN', type=str,
help='Your GitLab private token')
parser.add_argument('GITLAB_API_ENDPOINT', type=str,
help='GitLab API endpoint, e.g., https://gitlab.com/api/v4')
parser.add_argument('PROJECT_IDS', type=str,
help='Comma-separated list of project IDs or URL-encoded namespace/project names')
parser.add_argument('YAML_FILE', type=str, help='Path to your YAML file')
parser.add_argument('REPO_SECTIONS', type=str,
help='Comma-separated list of repo sections in the '
'YAML to process, e.g., OCA/web,'
'ThinkTankOdoo/main')

args = parser.parse_args()

fetch_and_update_yaml(args.GITLAB_TOKEN, args.GITLAB_API_ENDPOINT,
args.PROJECT_IDS, args.YAML_FILE, args.REPO_SECTIONS)
28 changes: 28 additions & 0 deletions bin/odoo_update_db_dates.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Set the current timestamp + 30 days for database.expiration_date
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM ir_config_parameter WHERE key = 'database.expiration_date') THEN
UPDATE ir_config_parameter
SET value = (current_date + interval '30 days')::date::text
WHERE key = 'database.expiration_date';
ELSE
INSERT INTO ir_config_parameter (key, value)
VALUES ('database.expiration_date', (current_date + interval '30 days')::date::text);
END IF;
END $$;

-- Set the current timestamp for database.create_date
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM ir_config_parameter WHERE key = 'database.create_date') THEN
UPDATE ir_config_parameter
SET value = current_date::text
WHERE key = 'database.create_date';
ELSE
INSERT INTO ir_config_parameter (key, value)
VALUES ('database.create_date', current_date::text);
END IF;
END $$;

-- Echo out the updated values
SELECT key, value FROM ir_config_parameter WHERE key IN ('database.create_date', 'database.expiration_date');
15 changes: 15 additions & 0 deletions bin/update_odoo_expiration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Check arguments
if [ "$#" -lt 2 ]; then
echo "Usage: $0 DB_NAME DB_USER [DB_HOST]"
exit 1
fi

# Assign arguments with default values
DB_NAME="$1"
DB_USER="$2"
DB_HOST="${3:-localhost}" # Default to localhost if not provided

# Execute the SQL commands
psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -a -f odoo_update_db_dates.sql