Skip to content

Commit 658801f

Browse files
committed
feat: Add setup-gh.sh script
**Description**: Adds the script setup-gh.sh which can be run to set up environment variables **Related Issue(s)**: Closes #86 Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
1 parent b423ba1 commit 658801f

2 files changed

Lines changed: 71 additions & 13 deletions

File tree

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
![App icon](images/FullSizeIcon.png)
22

33
# VersionTwo
4+
45
Hackathon project: CLI tool to generate static planning view of issues for better team planning
56

6-
# 🚀 Getting Started
7-
## 📦 Requirements
7+
## 🚀 Getting Started
8+
9+
### 📦 Requirements
10+
811
The following dependencies are required to run the program:
12+
913
- Python 3.x
1014
- `brew install python3`
1115
- Python `pyenv` and `pyenv-virtualenv`
12-
- `brew install pyenv pyenv-virtualenv`
16+
- `brew install pyenv pyenv-virtualenv`
1317
- GitHub Command Line Interface (CLI) `gh`
1418
- `brew install gh`
1519

16-
## 💻 Setup
20+
### 💻 Setup
21+
1722
- Authentication through `gh auth login`
18-
- Set the appropriate token permissions: `gh auth refresh --scopes read:project`
19-
- Note: The team must have `read` permissions on the Project Board in order to view the issues on the board.
20-
- Set the `GITHUB_TOKEN` environment variable: `export GITHUB_TOKEN=$(gh auth token)`
21-
- Set the `GITHUB_UNAME` environment variable: `export GITHUB_UNAME=$(gh auth status | grep "(GITHUB_TOKEN)" | cut -d " " -f9)`
23+
- Source the [setup-gh.sh](src/setup-gh.sh) script to configure your gh environment variables
24+
25+
```bash
26+
source src/setup-gh.sh # follow the prompts
27+
```
28+
29+
- Sets the appropriate token scopes: `read`.
30+
- Note: The team must have `read` permissions on the Project Board in order to view the issues on the board.
31+
- Sets the `GITHUB_TOKEN` environment variable.
32+
- Sets the `GITHUB_UNAME` environment variable.
2233
- Run `make install` inside the repo directory to configure the appropriate versions of dependencies.
2334

24-
## 🛠 Usage
35+
### 🛠 Usage
36+
2537
To run the main script, change to the current directory of the script, then run:
2638

2739
`python version2.py --output-file "<filename.json>" --temp-dir "<temp.dir>" --include-project <project name>`
2840

2941
See the `--help` menu for full list of filter functionality.
3042

31-
# Background
43+
## Background
44+
3245
GitHub users have issues assigned to themselves or a team they are a member of. These issues can be viewed on a
3346
Project board, which captures the issues in swim lanes. The Project board can only automate with a single organization,
3447
meaning users who work in more than one org do not have a single location to view all issues. This leads to fragmented
3548
planning and execution.
3649

37-
# How does it work?
50+
## How does it work?
3851

3952
```mermaid
4053
%% A · System-Architecture Diagram (≤25 nodes)
@@ -52,7 +65,8 @@ classDef api fill:#e3f2fd,stroke:#2196f3;
5265
classDef cli fill:#f1f8e9,stroke:#7cb342;
5366
```
5467

55-
# Our Solution
68+
## Our Solution
69+
5670
Our python script will query the GitHub API for all issues associated with the appropriate filters provided to the CLI
5771
tool. The output will be a static HTML page showing all issues in swim lanes. This provides a comprehensive overview
58-
of all issues the team or user has assigned.
72+
of all issues the team or user has assigned.

src/setup-gh.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#! /usr/bin/env bash
2+
3+
# This script sets up the authentication parameters for the GitHub CLI
4+
# that are needed to run the version2.py script.
5+
# It is assumed that the GitHub CLI is already installed and configured
6+
# on the system.
7+
# The script will update the user's github token to have the needed scopes,
8+
# set the token in the environment and pull in the gh users username as
9+
# another environment variable.
10+
11+
# Exit if not sourced
12+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
13+
echo "ERROR: This script must be sourced, not executed."
14+
echo "Usage: source ${BASH_SOURCE[0]}"
15+
exit 1
16+
fi
17+
18+
# Check if the GITHUB_TOKEN environment variable is already set
19+
set_gh_token() {
20+
# If not set, set the scopes for the token and set the enviornment variable
21+
gh auth refresh --scopes read:project
22+
23+
# Set the GITHUB_TOKEN environment variable
24+
export GITHUB_TOKEN=$(gh auth token)
25+
}
26+
27+
28+
configure_gh_env() {
29+
if [ -n "${GITHUB_TOKEN}" ]; then
30+
echo "GITHUB_TOKEN needs to be unset to update the token scopes."
31+
unset GITHUB_TOKEN
32+
fi
33+
34+
# set the gh_token
35+
set_gh_token
36+
37+
# set the gh_user
38+
export GITHUB_UNAME=$(gh api user --jq .login)
39+
40+
echo "GITHUB_TOKEN is set. Length is: ${#GITHUB_TOKEN}"
41+
echo "GITHUB_UNAME is set to: ${GITHUB_UNAME}"
42+
}
43+
44+
configure_gh_env

0 commit comments

Comments
 (0)