minor changes to changelog page
This commit is contained in:
parent
517f60f49d
commit
9419e15a4f
3 changed files with 113 additions and 40 deletions
|
|
@ -17,7 +17,6 @@ from .Events import Event, EventBus, Events
|
|||
from .ItemDTO import ItemDTO
|
||||
from .Singleton import Singleton
|
||||
from .Utils import validate_uuid
|
||||
from .version import APP_VERSION
|
||||
|
||||
LOG = logging.getLogger("notifications")
|
||||
|
||||
|
|
@ -138,6 +137,7 @@ class Notification(metaclass=Singleton):
|
|||
self._file: str = file or os.path.join(config.config_path, "notifications.json")
|
||||
self._client: httpx.AsyncClient = client or httpx.AsyncClient()
|
||||
self._encoder: Encoder = encoder or Encoder()
|
||||
self._version = config.version
|
||||
|
||||
if os.path.exists(self._file):
|
||||
try:
|
||||
|
|
@ -360,7 +360,7 @@ class Notification(metaclass=Singleton):
|
|||
"method": target.request.method.upper(),
|
||||
"url": target.request.url,
|
||||
"headers": {
|
||||
"User-Agent": f"YTPTube/{APP_VERSION}",
|
||||
"User-Agent": f"YTPTube/{self._version}",
|
||||
"X-Event-Id": ev.id,
|
||||
"X-Event": ev.event,
|
||||
"Content-Type": "application/json"
|
||||
|
|
|
|||
|
|
@ -421,6 +421,9 @@ class Config:
|
|||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
logging.getLogger("httpcore").setLevel(logging.INFO)
|
||||
|
||||
if self.version == "dev-master":
|
||||
self._version_via_git()
|
||||
|
||||
def _get_attributes(self) -> dict:
|
||||
attrs: dict = {}
|
||||
vClass: str = self.__class__
|
||||
|
|
@ -471,3 +474,59 @@ class Config:
|
|||
return YTDLP_VERSION
|
||||
except ImportError:
|
||||
return "0.0.0"
|
||||
|
||||
def _version_via_git(self):
|
||||
"""
|
||||
Updates the version of the application using git tags.
|
||||
This is used to set the version to the latest git tag.
|
||||
"""
|
||||
git_path: str = os.path.join(os.path.dirname(__file__), "..", "..", ".git")
|
||||
if not os.path.exists(git_path):
|
||||
logging.warning(f"Git directory '{git_path}' does not exist. Cannot determine version.")
|
||||
return
|
||||
|
||||
try:
|
||||
import subprocess
|
||||
|
||||
branch_result = subprocess.run( # noqa: S603
|
||||
["git", "rev-parse", "--abbrev-ref", "HEAD"], # noqa: S607
|
||||
cwd=os.path.dirname(git_path),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
if 0 != branch_result.returncode:
|
||||
logging.error(f"Git rev-parse failed: {branch_result.stderr.strip()}")
|
||||
return
|
||||
|
||||
branch_name: str = branch_result.stdout.strip()
|
||||
if not branch_name:
|
||||
logging.warning("Git branch name is empty.")
|
||||
return
|
||||
|
||||
commit_result = subprocess.run( # noqa: S603
|
||||
["git", "log", "-1", "--format=%ct_%H"], # noqa: S607
|
||||
cwd=os.path.dirname(git_path),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
if 0 != commit_result.returncode:
|
||||
logging.error(f"Git log failed: {commit_result.stderr.strip()}")
|
||||
return
|
||||
|
||||
commit_info: str = commit_result.stdout.strip()
|
||||
if not commit_info:
|
||||
logging.warning("Git commit info is empty.")
|
||||
return
|
||||
|
||||
commit_date, commit_sha = commit_info.split("_", 1)
|
||||
commit_date = time.strftime("%Y%m%d", time.localtime(int(commit_date)))
|
||||
commit_sha = commit_sha[:8]
|
||||
|
||||
self.version = f"{branch_name}-{commit_date}-{commit_sha}"
|
||||
logging.info(f"Application version set to '{self.version}' based on git data.")
|
||||
except Exception as e:
|
||||
logging.error(f"Error while getting git version: {e!s}")
|
||||
|
|
|
|||
|
|
@ -23,19 +23,19 @@
|
|||
<template v-if="!isLoading">
|
||||
<div class="logs-container">
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-12" v-for="(log, index) in logs" :key="log.tag">
|
||||
<div class="content">
|
||||
<div class="column p-0 m-0 is-12" v-for="(log, index) in logs" :key="log.tag">
|
||||
<div class="content p-0 m-0">
|
||||
<h1 class="is-4">
|
||||
<span class="icon"><i class="fas fa-code-branch" /></span>
|
||||
{{ formatTag(log.tag) }} <span class="tag has-text-success" v-if="isInstalled(log.tag)">Installed</span>
|
||||
{{ formatTag(log) }} <span class="tag has-text-success" v-if="isInstalled(log)">Installed</span>
|
||||
</h1>
|
||||
<hr>
|
||||
<ul>
|
||||
<li v-for="commit in log.commits" :key="commit.sha">
|
||||
<strong>{{ ucFirst(commit.message).replace(/\.$/, "") }}.</strong> -
|
||||
<small>
|
||||
<NuxtLink :to="`https://github.com/arabcoders/ytptube/commit/${commit.sha}`" target="_blank">
|
||||
<span class="has-tooltip" v-tooltip="`SHA: ${commit.sha} - Date: ${commit.date}`">
|
||||
<NuxtLink :to="`${REPO}/commit/${commit.full_sha}`" target="_blank">
|
||||
<span class="has-tooltip" v-tooltip="`SHA: ${commit.full_sha} - Date: ${commit.date}`">
|
||||
{{ moment(commit.date).fromNow() }}
|
||||
</span>
|
||||
</NuxtLink>
|
||||
|
|
@ -54,44 +54,47 @@
|
|||
<script setup>
|
||||
import moment from 'moment'
|
||||
|
||||
useHead({ title: 'CHANGELOG' })
|
||||
|
||||
const REPO_URL = "https://arabcoders.github.io/ytptube/CHANGELOG-{branch}.json?version={version}";
|
||||
const toast = useNotification();
|
||||
const toast = useNotification()
|
||||
const config = useConfigStore()
|
||||
|
||||
const logs = ref([]);
|
||||
useHead({ title: 'CHANGELOG' })
|
||||
|
||||
const PROJECT = 'ytptube'
|
||||
const REPO = `https://github.com/arabcoders/${PROJECT}`
|
||||
const REPO_URL = `https://arabcoders.github.io/${PROJECT}/CHANGELOG-{branch}.json?version={version}`
|
||||
|
||||
const logs = ref([])
|
||||
const api_version = ref('')
|
||||
const isLoading = ref(false);
|
||||
const isLoading = ref(false)
|
||||
const hashLength = ref(7)
|
||||
|
||||
const branch = computed(() => {
|
||||
const branch = String(api_version.value).split('-')[0] ?? 'master';
|
||||
return ['master', 'dev'].includes(branch) ? branch : 'master';
|
||||
});
|
||||
const branch = String(api_version.value).split('-')[0] ?? 'master'
|
||||
return ['master', 'dev'].includes(branch) ? branch : 'master'
|
||||
})
|
||||
|
||||
|
||||
const formatTag = tag => {
|
||||
const parts = tag.split('-');
|
||||
const formatTag = log => {
|
||||
const parts = log.tag.split('-')
|
||||
if (parts.length < 3) {
|
||||
return tag;
|
||||
return log.tag
|
||||
}
|
||||
const branch = parts[0];
|
||||
const date = parts[1];
|
||||
const shortSha = parts[2].substring(0, 7);
|
||||
return `${ucFirst(branch)}: ${moment(date, 'YYYYMMDD').format('YYYY-MM-DD')} - ${shortSha}`;
|
||||
|
||||
const branch = parts[0]
|
||||
const date = parts[1]
|
||||
const shortSha = log.full_sha.substring(0, hashLength.value)
|
||||
return `${ucFirst(branch)}: ${moment(date, 'YYYYMMDD').format('YYYY-MM-DD')} - ${shortSha}`
|
||||
}
|
||||
|
||||
|
||||
|
||||
watch(() => config.app.version, async value => {
|
||||
if (!value) {
|
||||
return
|
||||
}
|
||||
|
||||
api_version.value = value
|
||||
hashLength.value = value.split('-').pop().length
|
||||
|
||||
await nextTick();
|
||||
await loadContent();
|
||||
await nextTick()
|
||||
await loadContent()
|
||||
}, { immediate: true })
|
||||
|
||||
const loadContent = async () => {
|
||||
|
|
@ -99,25 +102,35 @@ const loadContent = async () => {
|
|||
return
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
isLoading.value = true
|
||||
try {
|
||||
const changes = await fetch(r(REPO_URL, { branch: branch.value, version: api_version.value }));
|
||||
logs.value = await changes.json();
|
||||
const changes = await fetch(REPO_URL.replace('{branch}', branch.value).replace('{version}', api_version.value))
|
||||
logs.value = await changes.json()
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
toast.error('error', 'Error', `Failed to fetch changelog. ${e.message}`);
|
||||
console.error(e)
|
||||
toast.error('error', 'Error', `Failed to fetch changelog. ${e.message}`)
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const isInstalled = tag => {
|
||||
const installed = String(api_version.value).split('-').pop();
|
||||
const tagHash = tag.split('-').pop();
|
||||
return tagHash.startsWith(installed);
|
||||
const isInstalled = log => {
|
||||
const installed = String(api_version.value).split('-').pop()
|
||||
|
||||
if (log.full_sha.startsWith(installed)) {
|
||||
return true
|
||||
}
|
||||
|
||||
for (const commit of log?.commits ?? []) {
|
||||
if (commit.full_sha.startsWith(installed)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
onMounted(() => loadContent());
|
||||
onMounted(() => loadContent())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
@ -130,6 +143,7 @@ onMounted(() => loadContent());
|
|||
}
|
||||
|
||||
hr {
|
||||
border-bottom: 1px solid #b2d1ff;
|
||||
background-color: unset;
|
||||
border-bottom: 1px solid var(--bulma-grey-light) !important
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in a new issue