This commit is contained in:
sangge-redmi 2024-01-22 00:43:51 +08:00
commit c1b28d7f43
5 changed files with 13 additions and 96 deletions

View File

@ -1,27 +1,10 @@
<p align="center"> # Dev Metrics in Readme
<img
src="https://socialify.git.ci/athul/waka-readme/image?description=1&font=Source%20Code%20Pro&forks=1&issues=1&name=1&owner=1&pulls=1&stargazers=1&theme=Auto"
alt="waka-readme"
width="640"
height="320"
/>
</p>
# Dev Metrics in Readme [![Unit Tests](https://github.com/athul/waka-readme/actions/workflows/testing.yml/badge.svg?branch=master)](https://github.com/athul/waka-readme/actions/workflows/testing.yml) fork from [waka-readme](https://github/athul/waka-readme)
edit for Gitea use.
[WakaTime](https://wakatime.com) coding metrics on your profile readme. [WakaTime](https://wakatime.com) coding metrics on your profile readme.
<!-- prettier-ignore-start -->
<picture>
<source srcset="https://github.com/athul/waka-readme/assets/38415384/60a6bcd0-01f8-421a-8730-7e872d216e09"
media="(prefers-color-scheme: dark)" />
<img src="https://github.com/athul/waka-readme/assets/38415384/29541cbc-0e39-47c4-93c2-514032b47276"
alt="new_secrets_actions" />
</picture>
<!-- prettier-ignore-end -->
:speech_balloon: **Forum** | [GitHub discussions][gh_discuss]
## New to WakaTime? ## New to WakaTime?
> Nope? Skip to [#Prep work](#prep-work). > Nope? Skip to [#Prep work](#prep-work).
@ -39,7 +22,7 @@ Alternatively, you can fetch data from WakaTime compatible services such as [Wak
## Prep Work ## Prep Work
A GitHub repository and a `README.md` file is required. We'll be making use of readme in the [profile repository][profile_readme]. A Gitea repository and a `README.md` file is required. We'll be making use of readme in the [profile repository][profile_readme].
- Save the `README.md` file after copy-pasting the following special comments. Your dev-metics will show up in between. - Save the `README.md` file after copy-pasting the following special comments. Your dev-metics will show up in between.
@ -51,31 +34,9 @@ A GitHub repository and a `README.md` file is required. We'll be making use of r
`<!--START_SECTION: -->` and `<!--END_SECTION: -->` are placeholders and must be retained as is. Whereas "`waka`" can be replaced by any alphanumeric string. See [#Tweaks](#tweaks) section for more. `<!--START_SECTION: -->` and `<!--END_SECTION: -->` are placeholders and must be retained as is. Whereas "`waka`" can be replaced by any alphanumeric string. See [#Tweaks](#tweaks) section for more.
- Navigate to your repo's `Settings`: - Navigate to your repo's `Settings`:
- Go to `Secrets` (at `https://github.com/USERNAME/USERNAME/settings/secrets/actions/new` by replacing the `USERNAME` with your own username) and add a new secret "_Named_" `WAKATIME_API_KEY` with your API key as it's "_Secret_". - Go to `Secrets` (at `https://your_gitea_url/username/.profile/settings/actions/secrets` by replacing the `USERNAME` with your own username) and add a new secret "_Named_" `WAKATIME_API_KEY` with your API key as it's "_Secret_".
<!-- prettier-ignore-start --> - Create a new workflow file named `waka-readme.yml` inside `.gitea/workflows/` folder of your profile repository.
<picture>
<source srcset="https://github.com/athul/waka-readme/assets/38415384/04dee9dc-65a1-43f9-9df4-7545646b9a72"
media="(prefers-color-scheme: dark)" />
<img src="https://github.com/athul/waka-readme/assets/38415384/9110cc3e-66cc-46ed-89d4-36644aa258e1"
alt="new_secrets_actions" />
</picture>
<!-- prettier-ignore-end -->
> If you're not using [profile repository][profile_readme], add another secret "_Named_" `GH_TOKEN` and in place of "_Secret_" insert your [GitHub token][gh_access_token].
- Go to `Workflow permissions` under `Actions` (at `https://github.com/USERNAME/USERNAME/settings/actions` by replacing the `USERNAME` with your own username) and set `Read and write permissions`.
<!-- prettier-ignore-start -->
<picture>
<source srcset="https://github.com/athul/waka-readme/assets/38415384/a1b86a0b-4065-4ff1-847b-b52e681bf247"
media="(prefers-color-scheme: dark)" />
<img src="https://github.com/athul/waka-readme/assets/38415384/de9cb7d0-fd40-43cf-8fed-7c6f57207788"
alt="new_secrets_actions" />
</picture>
<!-- prettier-ignore-end -->
- Create a new workflow file named `waka-readme.yml` inside `.github/workflows/` folder of your repository.
- Clear all existing contents, add following lines and save the file. - Clear all existing contents, add following lines and save the file.
```yml ```yml
@ -93,7 +54,7 @@ A GitHub repository and a `README.md` file is required. We'll be making use of r
name: WakaReadme DevMetrics name: WakaReadme DevMetrics
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: athul/waka-readme@master # this action name - uses: https://git.mamahaha.work/sangge/waka-readme@master # this action name
with: with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
``` ```
@ -161,13 +122,13 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# this action name # this action name
- uses: athul/waka-readme@master # do NOT replace with anything else - uses: https://git.mamahaha.work/sangge/waka-readme@master # do NOT replace with anything else
with: with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # optional if on profile readme GH_TOKEN: ${{ secrets.GH_TOKEN }} # optional if on profile readme
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} # required WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} # required
### meta ### meta
API_BASE_URL: https://wakatime.com/api # optional API_BASE_URL: https://wakatime.com/api # optional
REPOSITORY: YOUR_GITHUB_USERNAME/YOUR_REPOSITORY_NAME # optional REPOSITORY: YOUR_GITEA_USERNAME/YOUR_REPOSITORY_NAME # optional
### content ### content
SHOW_TITLE: true # optional SHOW_TITLE: true # optional
SECTION_NAME: waka # optional SECTION_NAME: waka # optional
@ -228,5 +189,3 @@ I am a fan of minimal designs and the profile readme is a great way to show off
[waka_plugins]: https://wakatime.com/plugins [waka_plugins]: https://wakatime.com/plugins
[waka_help]: https://wakatime.com/help/editors [waka_help]: https://wakatime.com/help/editors
[profile_readme]: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme [profile_readme]: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme
[gh_access_token]: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
[gh_discuss]: https://github.com/athul/waka-readme/discussions

View File

@ -39,10 +39,10 @@ ENV PATH="${PATH}:/root/.local/bin" \
PIP_DEFAULT_TIMEOUT=100 PIP_DEFAULT_TIMEOUT=100
# copy project files # copy project files
COPY --chown=root:root requirements.txt main.py /app/ -i https://pypi.tuna.tsinghua.edu.cn/simple COPY --chown=root:root pyproject.toml main.py /app/
# install dependencies # install dependencies
RUN python -m pip install /app/ RUN python -m pip install /app/ -i https://pypi.tuna.tsinghua.edu.cn/simple
# copy tests # copy tests
COPY --chown=root:root tests /app/tests/ COPY --chown=root:root tests /app/tests/

View File

@ -39,10 +39,10 @@ ENV PATH="${PATH}:/root/.local/bin" \
PIP_DEFAULT_TIMEOUT=100 PIP_DEFAULT_TIMEOUT=100
# copy project files # copy project files
COPY --chown=root:root requirements.txt main.py /app/ COPY --chown=root:root pyproject.toml main.py /app/
# install dependencies # install dependencies
RUN python -m pip install -r /app/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple RUN python -m pip install /app/ -i https://pypi.tuna.tsinghua.edu.cn/simple
# execute program # execute program
CMD python /app/main.py CMD python /app/main.py

View File

@ -1,3 +0,0 @@
faker>=21.0.0
requests>=2.31.0
py-gitea>=0.2.6

View File

@ -1,39 +0,0 @@
from gitea import *
import os
from base64 import b64decode, b64encode
URL = "https://git.mamahaha.work"
TOKEN = open("token.log", "r").read().strip()
gitea_connect = Gitea(URL, TOKEN)
print("Gitea Version: " + gitea_connect.get_version())
print("API-Token belongs to user: " + gitea_connect.get_user().username)
# Repository details
owner = "sangge" # Replace with the repository owner's username
repo_name = ".profile" # Replace with the repository name
# Get repository object
gitea_repo = Repository.request(gitea_connect, owner, repo_name)
print(gitea_repo.get_branches()[0].name)
readme_content = Content(gitea_connect)
readme_content.path = "README.md"
readme_content.type = Content.FILE
readme_data = gitea_repo.get_file_content(readme_content)
readme_contents = str(b64decode(readme_data), encoding="utf-8") + "123123"
# print(readme_contents)
readme_content = Content(gitea_connect)
readme_content.path = "README.md"
readme_content.type = Content.FILE
b64_readme_contents = b64encode(bytes(readme_contents, "utf-8"))
content = b64_readme_contents.decode("ascii")
acontent = gitea_repo.get_git_content()
readmes = [c for c in acontent if c.name == "README.md"]
# gitea_repo.change_file(readmes[0].name, readmes[0].sha, content)
print(content)
print(b64_readme_contents)