From 91f5f4e7aac653be7a0c9b349d878067ae0806f7 Mon Sep 17 00:00:00 2001 From: dsk-minchulahn Date: Fri, 11 Aug 2023 17:28:53 +0900 Subject: [PATCH] =?UTF-8?q?dashboard=20tab=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/main.py | 74 +++++++++++++++++++++++++------------------ dashboard/settings.py | 7 ++++ 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/dashboard/main.py b/dashboard/main.py index c2b7f10..311b279 100644 --- a/dashboard/main.py +++ b/dashboard/main.py @@ -1,5 +1,6 @@ import pandas as pd import streamlit as st +from datetime import datetime from streamlit_js_eval import streamlit_js_eval from settings import * from sidebar import show_sidebar @@ -7,42 +8,53 @@ from sidebar import show_sidebar def highlight_disabled_col(value): return 'background-color: #F0F2F6' -def init_page(): +if __name__=='__main__': + st.set_page_config( page_title='DataSaker Version Management', layout='wide' ) - st.header('DataSaker Version Management') - st.subheader(get_datasaker()) -if __name__=='__main__': + tab1, tab2 = st.tabs(["Deploy DataSaker", "Release Info"]) - init_page() + with tab1: + st.header('DataSaker') + st.write(f"##### {get_datasaker()}") + + col1, col2 = st.columns([7, 3]) + with col1: + st.subheader('Service') + + if st.button('Data Reload'): + git_pull() + streamlit_js_eval(js_expressions='parent.window.location.reload()') + + df = pd.DataFrame.from_dict(get_service()) + regex = '^release-[0-9]+.[0-9]+.[0-9]+$' + edited_df = st.data_editor( + df.style.applymap(highlight_disabled_col), + key='data_editor', + column_config={ + 'type': st.column_config.TextColumn('Type', disabled=True), + 'name': st.column_config.TextColumn('Name', disabled=True, width='medium'), + 'latest_candidate_version': st.column_config.TextColumn('Candidate Latest Version', disabled=True), + 'candidate_version': st.column_config.TextColumn('Candidate Version', validate=regex), + 'release_version': st.column_config.TextColumn('Release Version', validate=regex), + 'product_version': st.column_config.TextColumn('Product Version', validate=regex) + } + ) + with col2: + st.text('Edited Rows') + st.write(st.session_state['data_editor']['edited_rows']) - col1, col2 = st.columns([7, 3]) - with col1: - st.subheader('Service') - - if st.button('Data Reload'): - git_pull() - streamlit_js_eval(js_expressions='parent.window.location.reload()') - - df = pd.DataFrame.from_dict(get_service()) - regex = '^release-[0-9]+.[0-9]+.[0-9]+$' - edited_df = st.data_editor( - df.style.applymap(highlight_disabled_col), - key='data_editor', - column_config={ - 'type': st.column_config.TextColumn('Type', disabled=True), - 'name': st.column_config.TextColumn('Name', disabled=True, width='medium'), - 'latest_candidate_version': st.column_config.TextColumn('Candidate Latest Version', disabled=True), - 'candidate_version': st.column_config.TextColumn('Candidate Version', validate=regex), - 'release_version': st.column_config.TextColumn('Release Version', validate=regex), - 'product_version': st.column_config.TextColumn('Product Version', validate=regex) - } - ) - with col2: - st.text('Edited Rows') - st.write(st.session_state['data_editor']['edited_rows']) - + with tab2: + releases = get_github_releases() + for release in releases: + st.write(f"### {release['name']}") + st.write(release['html_url']) + st.write(datetime.strptime(release['published_at'], "%Y-%m-%dT%H:%M:%SZ")) + # st.write(datetime.strptime(release['published_at'], "%Y-%m-%dT%H:%M:%SZ").strftime('%Y-%m-%d %H:%M:%S')) + st.write(release['body'].replace('#', '')) + st.divider() + show_sidebar(df, edited_df) \ No newline at end of file diff --git a/dashboard/settings.py b/dashboard/settings.py index 9207fed..f9284c4 100644 --- a/dashboard/settings.py +++ b/dashboard/settings.py @@ -18,6 +18,13 @@ def get_commit_id(): def get_tags(): return repo.tags +def get_github_releases(): + api_url = 'https://api.github.com/repos/cloudmoa/dsk-version-management/releases' + github_token = os.environ.get('GITHUB_TOKEN') + headers = {'Authorization': f'Bearer {github_token}', 'Accept': 'application/vnd.github.v3+json'} + releases = requests.get(api_url, headers=headers).json() + return releases + def diff(): if len(repo.index.diff(repo.head.commit)) > 0: return True