Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+] --repo flag to fetch Repository info #13

Open
Azathothas opened this issue Oct 6, 2024 · 0 comments
Open

[+] --repo flag to fetch Repository info #13

Azathothas opened this issue Oct 6, 2024 · 0 comments

Comments

@Azathothas
Copy link

Azathothas commented Oct 6, 2024

Hi, a --repo flag would benefit this tool immensely,
the api request would be similar.
and the output (the default neofetch style) could be like this:

$ ghfetch --repo="mullvad/mullvadvpn-app"
#OR: 
$ ghfetch --repo="https://github.com/mullvad/mullvadvpn-app"

#Note, some of these were manually added since this repo I used as an example didn't have all the fields
..................................................
..................................................
.........................       ..................
....................... ..-===--..  ..............
......................--+########+=-  ............
................ ...-+@@=###########+. ...........
...................-=@@+=#############. ..........
...............--=+##+++##############+ ..........  Repo: mullvadvpn-app
.. =##++=++++++===---+################+ ..........  -------------
...-++++++++++++++++=--=##############- ..........  Name: mullvadvpn-app
.....-=+++++++++++++++=---+##########= ...........  Author: mullvad
.....-=+++++++++++++++=---+##########= ...........  Description: The Mullvad VPN client app for desktop and mobile 
.......=+++++++++++++++++=--==+#####= ............  Stars: 4995 ★
....... -=++++++++++++++++++==----=+. ............  Updated: 2024-09-26T11:09:18Z
........ .-=+++++++++++++++++++++==...............  Release: 2024-06-16T14:11:14Z
.......... .-=++++++++++=-==+++++++=..............  Version (Tag): v1.2.0
............  .++=====--==+++++++++=..............  Langauge: Rust,Swift,Kotlin
...............=+=====+++++++++++++=..............  License: GPL-3.0 license
...............=+=====+++++++++++++=..............  Issues (Open): 316
.............. -++++++++++++++++++++- ............  PR (Open): 25
.............. -++++++++++++++++++++- ............  Topics: vpn, privacy
.............. -++++++++++++++++++++- ............  -------------
..............=++++++++++++++++++++++-............████████████████████████
.............+++++++++++++++++++++++++=...........
.............-=+++++++++++++++++++++=-............
............. ..-==+++++++++++++==-.. ............
................  ...---------...  ...............
....................           ..........

The API, using curl looked somewhat like this:

#I copy pasted this from a script I was using, so I am sorry if this looks awful            
            
  REPO_NAME="$(echo ${REPO_URL} | sed 's|^https://github.com/||' | sed 's/\s//g' | sed 's/|//g' | tr -d '[:space:]')" && export REPO_NAME="${REPO_NAME}"
  REPO_METADATA="$(curl -qfsSL "https://api.github.com/repos/$REPO_NAME" -H "Authorization: Bearer $GITHUB_TOKEN" 2>/dev/null)" && export REPO_METADATA="$REPO_METADATA"
  RELEASE_METADATA="$(curl -qfsSL "https://api.github.com/repos/$REPO_NAME/releases/latest" -H "Authorization: Bearer $GITHUB_TOKEN" 2>/dev/null | jq '.assets=""')" && export RELEASE_METADATA="$RELEASE_METADATA"
 #Parse
  REPO_AUTHOR="$(echo $REPO_METADATA | jq -r '.owner.login')" && export REPO_AUTHOR="$REPO_AUTHOR"
  REPO_DESCRIPTION="$(echo $REPO_METADATA | jq -r '.description')" && export REPO_DESCRIPTION="$REPO_DESCRIPTION"
  REPO_LANGUAGE="$(echo $REPO_METADATA | jq -r '.language' )" && export REPO_LANGUAGE="$REPO_LANGUAGE"
  REPO_LICENSE="$(echo $REPO_METADATA | jq -r '.license.name')" && export REPO_LICENSE="$REPO_LICENSE"
  LAST_UPDATED="$(echo $REPO_METADATA | jq -r '.pushed_at')" && export LAST_UPDATED="$LAST_UPDATED"
 #If Releases don't exist, use tags
  if [ -z "$RELEASE_METADATA" ]; then
     PKG_VERSION="$(curl -qfsSL "https://api.github.com/repos/$REPO_NAME/tags" -H "Authorization: Bearer $GITHUB_TOKEN" 2>/dev/null | jq -r '.[0].name')" && export PKG_VERSION="$PKG_VERSION"
     PKG_RELEASED="$(curl -qfsSL "https://api.github.com/repos/$REPO_NAME/git/refs/tags/$PKG_VERSION" -H "Authorization: Bearer $GITHUB_TOKEN" 2>/dev/null | jq '.object.url' | xargs curl -qfsSL -H "Authorization: Bearer $GITHUB_TOKEN" 2>/dev/null | jq -r '.committer.date')" && export PKG_RELEASED="$PKG_RELEASED"
  else
     PKG_VERSION="$(echo $RELEASE_METADATA | jq -r '.tag_name' )" && export PKG_VERSION="$PKG_VERSION"
     PKG_RELEASED="$(echo $RELEASE_METADATA | jq -r '.published_at')" && export PKG_RELEASED="$PKG_RELEASED"
  fi
  REPO_STARS="$(echo $REPO_METADATA | jq -r '.stargazers_count')" && export REPO_STARS="$REPO_STARS"
  REPO_TOPICS="$(echo "$REPO_METADATA" | jq -c -r '.topics')" && export REPO_TOPICS="$REPO_TOPICS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant