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

feat: make it work with OAuth 2 #4

Merged
merged 47 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3fb53f3
eod commit
WilliamBergamin Jan 12, 2024
6bb085c
Introduce logic for PAT
WilliamBergamin Jan 15, 2024
97e64e3
Now actually make it work
WilliamBergamin Jan 15, 2024
ba79ca8
update
WilliamBergamin Jan 18, 2024
b637c15
Make it work!!!
WilliamBergamin Jan 26, 2024
e27decb
Add this stuff in
WilliamBergamin Feb 6, 2024
7ce8437
Update manifest.json
WilliamBergamin Feb 7, 2024
af046a3
OAuth works
WilliamBergamin May 15, 2024
7005c9a
its getting better
WilliamBergamin May 15, 2024
09fa950
things are looking good
WilliamBergamin May 15, 2024
2a5b2a2
The installation store works
WilliamBergamin May 16, 2024
96947de
Add a jira client
WilliamBergamin May 16, 2024
8faefc4
improve the sample
WilliamBergamin May 16, 2024
a6efc5a
Allow connecting and disconnecting accounts
WilliamBergamin May 16, 2024
6102cbb
Improve the OAuth state store
WilliamBergamin May 16, 2024
966e70d
Its taking shape
WilliamBergamin May 16, 2024
fd50dd9
It all works
WilliamBergamin May 16, 2024
97a9611
Its works
WilliamBergamin May 16, 2024
3dc5204
clean up
WilliamBergamin May 16, 2024
701aeb6
Improve the secret headers
WilliamBergamin May 28, 2024
9562159
Improve the behavior
WilliamBergamin May 28, 2024
cecf18c
Improve mocks
WilliamBergamin May 28, 2024
a883804
Improve tests
WilliamBergamin May 28, 2024
5b386d0
improve project
WilliamBergamin May 29, 2024
4e4afea
improve code
WilliamBergamin May 29, 2024
a86faf2
fix test
WilliamBergamin May 29, 2024
79d74e1
Update pytest.yml
WilliamBergamin May 29, 2024
db39c3d
We don't need black validation
WilliamBergamin May 29, 2024
e2481a5
Improve the readme
WilliamBergamin May 29, 2024
8ab145d
use ruff
WilliamBergamin May 29, 2024
7adde4c
Update jira/client.py
WilliamBergamin May 30, 2024
71f7173
rename with jira prefixes
WilliamBergamin May 30, 2024
f209af8
Use a file state store instead of a memory one
WilliamBergamin May 30, 2024
58e6845
Add comments
WilliamBergamin May 30, 2024
027d36b
create a utils folder
WilliamBergamin May 30, 2024
46710f6
use a global context
WilliamBergamin May 30, 2024
ad02d21
Improve tests
WilliamBergamin May 30, 2024
82550e2
Improve based on feedback
WilliamBergamin May 30, 2024
bb1ec0c
Update requirements.txt
WilliamBergamin May 30, 2024
c69b1c3
Improve tests
WilliamBergamin May 30, 2024
109b687
Merge branch 'Initial-poc-with-workflow' of https://github.com/slack-…
WilliamBergamin May 30, 2024
9a839c0
Update README.md
WilliamBergamin May 30, 2024
6b4f4e8
Merge branch 'Initial-poc-with-workflow' of https://github.com/slack-…
WilliamBergamin May 30, 2024
18f3257
update based on feedback
WilliamBergamin May 30, 2024
34670e0
update gitignore
WilliamBergamin May 30, 2024
24bd6e1
small improvements
WilliamBergamin May 31, 2024
62a7545
Fix comment
WilliamBergamin May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ updates:
interval: "monthly"
labels:
- "pip"
- "dependencies"
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved
- "dependencies"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
29 changes: 0 additions & 29 deletions .github/workflows/black.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/flake8.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Linting validation using ruff

on:
push:
branches: [main]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
python-version: ["3.12"]
zimeg marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip
pip install -r requirements.txt
- name: Lint with ruff
run: |
ruff check
28 changes: 28 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Testing with pytest

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pytest tests/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ tmp.txt
logs/
*.db
.pytype/

#tmp
.slack
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved
data
7 changes: 7 additions & 0 deletions .sample.env
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
JIRA_BASE_URL=http://localhost:8080
SECRET_HEADER_KEY=My-Header
SECRET_HEADER_VALUE=a123
JIRA_CLIENT_ID=abc134
JIRA_CLIENT_SECRET=abc134
APP_BASE_URL=https://this-si-my-app
APP_HOME_PAGE_URL=https://slack.workspace/archives/bot-id
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved
104 changes: 77 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,113 @@
# Bolt for Python Automation Template App
# Bolt for Python Jira Functions

This is a generic Bolt for Python template app used to build out Slack automations.
This is a Bolt for Python app used to interact with Jira Server.

Before getting started, make sure you have a development workspace where you have permissions to install apps. If you don’t have one setup, go ahead and [create one](https://slack.com/create).
Before getting started, make sure you have a development workspace where you
have permissions to install apps. If you don’t have one setup, go ahead and
[create one](https://slack.com/create).

## Installation

#### Create a Slack App
### Install the Slack CLI

1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose "From an app manifest"
2. Choose the workspace you want to install the application to
3. Copy the contents of [manifest.json](./manifest.json) into the text box that says `*Paste your manifest code here*` (within the JSON tab) and click *Next*
4. Review the configuration and click *Create*
5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard.
To use this template, you need to install and configure the Slack CLI.
Step-by-step instructions can be found in our
[Quickstart Guide](https://api.slack.com/automation/quickstart).

#### Environment Variables

Before you can run the app, you'll need to store some environment variables.

1. Rename `.env.sample` to `.env`
2. Open your apps configuration page from [this list](https://api.slack.com/apps), click *OAuth & Permissions* in the left hand menu, then copy the *Bot User OAuth Token* into your `.env` file under `SLACK_BOT_TOKEN`
3. Click *Basic Information* from the left hand menu and follow the steps in the *App-Level Tokens* section to create an app-level token with the `connections:write` scope. Copy that token into your `.env` as `SLACK_APP_TOKEN`.

### Setup Your Local Project
### Create a Slack App

```zsh
# Clone this project onto your machine
git clone https://github.com/slack-samples/bolt-python-automation-template.git
slack create my-app -t https://github.com/slack-samples/bolt-python-jira-functions.git
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved

# Change into this project directory
cd bolt-python-automation-template
# Change into the project directory
cd my-app

# Set up virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt
```

### Environment Variables

Before you can run the app, you'll need to store some environment variables.

1. Rename `.env.sample` to `.env`
2. Follow these
[Jira Instruction](https://confluence.atlassian.com/adminjiraserver0909/configure-an-incoming-link-1251415519.html)
to get the `Client ID` (`JIRA_CLIENT_ID`) and `Client secret`
(`JIRA_CLIENT_SECRET`) values.
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved
3. Populate the other environment variable value with proper values.

### Running Your Project Locally

You'll know an app is the development version if the name has the string
`(local)` appended.

```zsh
# Run Bolt server
slack run

INFO:slack_bolt.App:Starting to receive messages from a new connection
```

To stop running locally, press `<CTRL> + C` to end the process.

#### Linting

```zsh
# Run flake8 from root directory for linting
flake8 *.py
# Run ruff from root directory for linting
ruff check

# Run ruff from root directory for code formatting
ruff format
ruff check --fix
```

## Testing

For an example of how to test a function, see
`tests/functions/test_create_issue.py`.

Run all tests with:

# Run black from root directory for code formatting
black .
```zsh
pytest tests/
```

## Project Structure
WilliamBergamin marked this conversation as resolved.
Show resolved Hide resolved

### `.slack/`

Contains `apps.dev.json` and `apps.json`, which include installation details for
development and deployed apps.

### `manifest.json`

`manifest.json` is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app.
`manifest.json` is a configuration for Slack apps. With a manifest, you can
create an app with a pre-defined configuration, or adjust the configuration of
an existing app.

### `app.py`

`app.py` is the entry point for the application and is the file you'll run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests.
`app.py` is the entry point for the application and is the file you'll run to
start the server. This project aims to keep this file as thin as possible,
primarily using it as a way to route inbound requests.

### `/listeners`

Every incoming request is routed to a "listener". Inside this directory, we
group each listener based on the Slack Platform feature used, so
`/listeners/shortcuts` handles incoming
[Shortcuts](https://api.slack.com/interactivity/shortcuts) requests,
`/listeners/views` handles
[View submissions](https://api.slack.com/reference/interaction-payloads/views#view_submission)
and so on.

### `slack.json`

Used by the CLI to interact with the project's SDK dependencies. It contains
script hooks that are executed by the CLI and implemented by the SDK.
Loading