GithubHelp home page GithubHelp logo

hoijui / is-git-forge-public Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 24 KB

Figures out whether a git repo is public, given its WebUI URL.

License: GNU Affero General Public License v3.0

Shell 100.00%
cli git gitea github gitlab sourcehut

is-git-forge-public's Introduction

is-git-forge-public

License: AGPL-3.0-or-later REUSE status

In cooperation with FabCity Hamburg In cooperation with Open Source Ecology Germany

What is this

Given the URL to a git repository on a known forge site - or at least using a known forge software - returns whether the project is public or not. Non-public could be private, internal, unlisted, bad URL, non repository URL, or possibly something else.

It does that by downloading the HTML of the Web-UI of the repository, from which it then extracts the necessary info. This info is then presenting it in a uniform way, independent of the forge site, the software it is running, and the actual findings of the evaluation.

Why this way, instead of using API(s)?
This is much simpler, using a uniform technique for any URL given. A simple script, easily extendable to other sites, requiring no tokens or anything else for authentication. The downside of course, is that it might be less robust over time, and that it will likely not fail-fast.

We try to mitigate that downside, by running unit tests once a week.

Supported sites/forge software:

Usage

$ is-git-forge-public --help

Usage:
  is-git-forge-public [OPTION...] <REPO-WEB-URL>
Options:
  -h, --help              Print this usage help and exits.
  -f, --fail              Return failure if download returned status 404.
                          While that might indicate a bad URL,
                          it is also the case when trying to access
                          a private repo without authentication.
  -c, --check [FORGE]     Instead of using the checks for all forges,
                          use only a specific one.
                          Supported: 'github', 'gitlab', 'gitea', 'sourcehut'
Examples:
  is-git-forge-public --help
  is-git-forge-public "https://github.com/user/repo"
  is-git-forge-public --check github "https://github.com/user/repo"

Examples

Public repo:

$ is-git-forge-public "https://github.com/hoijui/MeditationBench"
true
public

Private repo:

$ is-git-forge-public "https://github.com/hoijui/tst-private"
WARN: Failed fetching the HTML content of URL:
WARN: 'https://github.com/hoijui/tst-private'
WARN: This could be due to:
WARN: - private repo URL
WARN: - not a repo URL
WARN: - no internet access
WARN: - authentication required
WARN: - mistyped repo URL
WARN: - ...
false
unknown

In this second example, all the WARN: ... lines go to stderr. This is where all logging goes (in alignment with CLI best-practice), so that on stdout, we only ever get these two lines of output:

Line Number Name Machine-Readable Type Valid Values (regex) Example
1 Is Public? yes boolean `true false`
2 State no string .* unknown

In most cases, this script is probably going to be used by other software, in which case, you are probably only interested in the first line of stdout, which in BASH you might use like this:

repo_url="https://github.com/hoijui/MeditationBench"
#repo_url="https://github.com/hoijui/tst-private"

is_public="$(is-git-forge-public "$repo_url" 2> /dev/null | head -n 1)"

if $is-git-forge-public
then
    echo "Git repo '$repo_url' is public!"
else
    echo "Git repo '$repo_url' is *not* public!"
fi

is-git-forge-public's People

Contributors

hoijui avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.