forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_notes.py
83 lines (71 loc) · 3.47 KB
/
release_notes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
import logging
import os
from typing import List
from pytablewriter import MarkdownTableWriter
from git.git_repository import GitRepository
from manifests.input_manifest import InputComponentFromSource, InputManifest
from release_notes_workflow.release_notes_component import ReleaseNotesComponents
from system.temporary_directory import TemporaryDirectory
class ReleaseNotes:
def __init__(self, manifest: InputManifest, date: str, action_type: str) -> None:
self.manifest = manifest
self.date = date
self.action_type = action_type
def table(self) -> MarkdownTableWriter:
table_result = []
for component in self.manifest.components.select():
if component.name == 'OpenSearch' or component.name == 'OpenSearch-Dashboards' or component.name == 'notifications-core':
continue
if hasattr(component, "repository"):
table_result.append(self.check(component)) # type: ignore[arg-type]
# Sort table_result based on Repo column
table_result.sort(key=lambda x: (x[0], x[1]) if len(x) > 1 else x[0])
if self.action_type == "check":
headers = ["Repo", "Branch", "CommitID", "Commit Date", "Release Notes Exists"]
elif self.action_type == "compile":
headers = ["Repo", "Branch", "CommitID", "Commit Date", "Release Notes Exists", "URL"]
else:
raise ValueError("Invalid action_type. Use 'check' or 'compile'.")
writer = MarkdownTableWriter(
table_name=f" {self.manifest.build.name} CommitID(after {self.date}) & Release Notes info",
headers=headers,
value_matrix=table_result
)
return writer
def check(self, component: InputComponentFromSource) -> List:
results = []
with TemporaryDirectory(chdir=True) as work_dir:
results.append(component.name)
results.append(f"[{component.ref}]")
with GitRepository(
component.repository,
component.ref,
os.path.join(work_dir.name, component.name),
component.working_directory,
) as repo:
logging.debug(f"Checked out {component.name} into {repo.dir}")
release_notes = ReleaseNotesComponents.from_component(component, self.manifest.build.version, repo.dir)
commits = repo.log(self.date)
if len(commits) > 0:
last_commit = commits[-1]
results.append(last_commit.id)
results.append(last_commit.date)
else:
results.append(None)
results.append(None)
results.append(release_notes.exists())
if(release_notes.exists()):
releasenote = os.path.basename(release_notes.full_path)
repo_name = component.repository.split("/")[-1].split('.')[0]
repo_ref = component.ref.split("/")[-1]
url = f"https://raw.githubusercontent.com/opensearch-project/{repo_name}/{repo_ref}/release-notes/{releasenote}"
results.append(url)
else:
results.append(None)
return results