-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from muselab-d2x/jlantz/parse-metadata-deletions
Parse metadata deletions in beta-test-env workflow
- Loading branch information
Showing
5 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import requests | ||
import json | ||
import os | ||
|
||
def create_github_check(metadata_deletions): | ||
repo = os.getenv('GITHUB_REPOSITORY') | ||
sha = os.getenv('GITHUB_SHA') | ||
app_id = os.getenv('GITHUB_APP_ID') | ||
app_key = os.getenv('GITHUB_APP_KEY') | ||
|
||
url = f"https://api.github.com/repos/{repo}/check-runs" | ||
headers = { | ||
"Authorization": f"Bearer {app_key}", | ||
"Accept": "application/vnd.github.v3+json" | ||
} | ||
data = { | ||
"name": "Package Metadata Deletions", | ||
"head_sha": sha, | ||
"status": "completed", | ||
"conclusion": "neutral", | ||
"output": { | ||
"title": "Metadata Deletions", | ||
"summary": "The following metadata deletions were found:", | ||
"text": json.dumps(metadata_deletions, indent=2) | ||
} | ||
} | ||
|
||
if metadata_deletions: | ||
data["conclusion"] = "action_required" | ||
|
||
response = requests.post(url, headers=headers, json=data) | ||
response.raise_for_status() | ||
|
||
if __name__ == "__main__": | ||
with open('metadata_deletions.json') as f: | ||
metadata_deletions = json.load(f) | ||
create_github_check(metadata_deletions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import re | ||
import json | ||
|
||
def parse_metadata_deletions(log_content): | ||
deletions = [] | ||
deletion_section = False | ||
|
||
for line in log_content.splitlines(): | ||
if "Deleting metadata:" in line: | ||
deletion_section = True | ||
continue | ||
if deletion_section: | ||
if line.strip() == "": | ||
break | ||
match = re.match(r"\s*(\w+):\s*(\w+)", line) | ||
if match: | ||
metadata_type, metadata_name = match.groups() | ||
deletions.append({"type": metadata_type, "name": metadata_name}) | ||
|
||
return json.dumps(deletions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
parse_metadata_deletions() { | ||
local log_content="$1" | ||
local deletions=() | ||
local deletion_section=false | ||
|
||
while IFS= read -r line; do | ||
if [[ "$line" == *"Deleting metadata:"* ]]; then | ||
deletion_section=true | ||
continue | ||
fi | ||
if $deletion_section; then | ||
if [[ -z "$line" ]]; then | ||
break | ||
fi | ||
if [[ "$line" =~ ^[[:space:]]*([[:alnum:]]+):[[:space:]]*([[:alnum:]]+)$ ]]; then | ||
local metadata_type="${BASH_REMATCH[1]}" | ||
local metadata_name="${BASH_REMATCH[2]}" | ||
deletions+=("{\"type\":\"$metadata_type\",\"name\":\"$metadata_name\"}") | ||
fi | ||
fi | ||
done <<< "$log_content" | ||
|
||
echo "[${deletions[*]}]" | ||
} | ||
|
||
log_content=$(cat) | ||
parse_metadata_deletions "$log_content" |