This script is used to retrieve the package name from a specific repository, using the GitHub's GraphQL API. More info about GitHub's graphQL in this link: GraphQL API Documentation. Also, there is the GitHub Explorer where you can write and test your GraphQL queries to the GitHub. More information can be found at the following link: GraphQL Explorer.
-
In order to use the script, simply clone the current repo or download as
zip
file the code and extract the content. Inside the folder repository-package-name there is the main shell script with the namefindRepoPackageName.sh
, and some other files. -
The script takes
3 arguments
in order to work properly:
pathToFolder
: which is the path to the project from the Github, from which you want to retrieve the name of package.
owner
: which is the owner of the repository. It could be an organisation or personal account.
inputToken
: a properly configured token from Github which has at least the scope ofwrite:packages
, otherwise the API call will not work.
Below there is a board of the possible outcomes for using the findRepoPackageName.sh
:
arguments | example | outcome |
---|---|---|
none | ./findRepoPackageName | You should provide the path, the owner of the repo and the token with the correct access rights |
pathToProject ownerName | ./findRepoPackageName pathToProject username | You should provide the token with the correct access rights as the third argument |
All arguments provided but not correct | ./findRepoPackageName pathToProject username wrongToken | The script will return an empty answer, as it couldn't find any packages with those credentials (the token is wrong) |
All arguments are correct | ./findRepoPackageName pathToProject username correctToken | The script will return the package name that it is in the repo that was provided from the path previously |
In case you want to run the tests locally make sure the shunit2
tool is installed in your machine. To check if it is already installed you can open a new terminal window and execute
the following command:
$ cat $(which shunit2) | grep "SHUNIT_VERSION"
If it is installed you will get the following message:
command [ -n "${SHUNIT_VERSION:-}" ] && exit 0
SHUNIT_VERSION='2.1.8'
If it is not installed you will get the following message:
shunit2 not found
In order to install it on Ubuntu or MacOS software environment, you may use the following command in a new terminal window:
Linux\Ubuntu
$ sudo apt-get update
$ sudo apt-get -y install shunit2
MacOS
$ brew install shunit2
Important
The tool brew
is assumed that it is already installed in MacOS machine.
After the shunit2
tool is properly installed in your machine, to run the tests execute the following command from the
root path of the current project folder:
./tests/test.sh . username githubToken com.test-package.using-java-maven
Replace the username with yours, and the githubToken with the one that you created and at least
has the write:packages
scope.
Also notice the .
, which is preceding the username, and states from the current directory
. That's why when you want
to add any new scenarios, in order to test them locally you should execute the script from the current's project root folder.
The com.test-package.using-java-maven
is a package that was created for testing purposes, e.g. the script runs
successfully, finds and returns the proper package.
The package can be found here