forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_notes.py
59 lines (51 loc) · 2.28 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
# 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) -> None:
self.manifest = manifest
self.date = date
def table(self) -> MarkdownTableWriter:
table_result = []
for component in self.manifest.components.select():
if type(component) is InputComponentFromSource:
table_result.append(self.check(component))
writer = MarkdownTableWriter(
table_name=f" {self.manifest.build.name} CommitID(after {self.date}) & Release Notes info",
headers=["Repo", "Branch", "CommitID", "Commit Date", "Release Notes"],
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(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())
return results