-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APP-3167] Add flask app based on the code from slack bot repo
- Loading branch information
Showing
16 changed files
with
424 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DataRobot Applications Team <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, sex characteristics, gender identity and expression, | ||
level of experience, education, socio-economic status, nationality, personal | ||
appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at [email protected]. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
||
For answers to common questions about this code of conduct, see | ||
https://www.contributor-covenant.org/faq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Contributing Guidelines | ||
|
||
Guidelines for developing and contributing to this project. | ||
|
||
## List of project maintainers | ||
|
||
- [Kim Dehmlow](https://github.com/kideh88) | ||
|
||
|
||
## Opening new issues | ||
|
||
- Before opening a new issue check if there are any existing FAQ entries (if one exists), issues or pull requests that match your case | ||
- Open an issue, and make sure to label the issue accordingly - bug, improvement, feature request, etc... | ||
- Be as specific and detailed as possible | ||
|
||
## Did you find a bug? | ||
|
||
- Do not open up a GitHub issue if the bug is a security | ||
vulnerability, instead email the maintainers directly or email | ||
[email protected] if they do not respond within | ||
seven days | ||
- Ensure the bug was not already reported in the projects Issues section | ||
- Open an issue as described above | ||
|
||
## Responding to issues and pull requests | ||
|
||
This project's maintainers will make every effort to respond to any | ||
open issues as soon as possible. | ||
|
||
If you don't get a response within sevent days of creating your issue or | ||
pull request, please send us an email at [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## This repository is public. Do not put any private DataRobot or customer data: code, datasets, model artifacts, .etc. | ||
|
||
## Rationale | ||
|
||
_What is this pull request for?_ | ||
|
||
### Summary of Changes | ||
|
||
_In general, what was changed? Screenshots are welcome too!_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Reporting Security Issues | ||
|
||
DataRobot takes the security of our product and any public code or integrations very seriously, if you have discovered a potential security vulnerability please reach out to [email protected] / [email protected] or open a new issue on the repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Notify Applications team on "Ready for review" PRs | ||
|
||
on: | ||
pull_request: | ||
types: [labeled] | ||
|
||
jobs: | ||
notify-slack: | ||
if: github.event.label.name == 'Ready for review' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Send notification to Slack | ||
run: | | ||
SLACK_WEBHOOK_URL="${{ secrets.SLACK_WEBHOOK_URL }}" | ||
PR_NR="${{ github.event.pull_request.number }}" | ||
PR_URL="${{ github.event.pull_request.html_url }}" | ||
PR_TITLE="${{ github.event.pull_request.title }}" | ||
PR_AUTHOR="${{ github.event.pull_request.user.login }}" | ||
PR_ADDITIONS="${{ github.event.pull_request.additions }}" | ||
PR_DELETIONS="${{ github.event.pull_request.deletions }}" | ||
REPO_NAME="${{ github.event.repository.name }}" | ||
curl -X POST -H 'Content-type: application/json' \ | ||
--data "{ | ||
\"text\": \"*Pull Request Ready for Review!*\", | ||
\"blocks\": [ | ||
{ | ||
\"type\": \"section\", | ||
\"text\": { | ||
\"type\": \"mrkdwn\", | ||
\"text\": \"@applications-team: :rocket: PR by ${PR_AUTHOR} needs a review: \`+${PR_ADDITIONS} -${PR_DELETIONS}\` <${PR_URL}|${REPO_NAME}#${PR_NR}: ${PR_TITLE}>\" | ||
} | ||
} | ||
] | ||
}" \ | ||
$SLACK_WEBHOOK_URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Periodic PR Reminders | ||
|
||
on: | ||
schedule: | ||
- cron: '0 */3 * * *' # Runs every 3 hours | ||
|
||
jobs: | ||
reminder: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Send reminders for PRs with "Ready for review" | ||
run: | | ||
SLACK_WEBHOOK_URL="${{ secrets.SLACK_WEBHOOK_URL }}" | ||
# Fetch PRs with "Ready for review" label | ||
PRS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues?labels=Ready%20for%20review&state=open&per_page=100") | ||
PR_COUNT=$(echo $PRS | jq '. | length') | ||
if [ "$PR_COUNT" -eq 0 ]; then | ||
echo "No PRs with 'Ready for review' label found." | ||
exit 0 | ||
fi | ||
# Iterate over each PR and send a reminder | ||
for row in $(echo "${PRS}" | jq -r '.[] | @base64'); do | ||
_jq() { | ||
echo ${row} | base64 --decode | jq -r ${1} | ||
} | ||
PR_NUMBER=$(_jq '.number') | ||
PR_TITLE=$(_jq '.title') | ||
PR_URL=$(_jq '.html_url') | ||
PR_AUTHOR=$(_jq '.user.login') | ||
PR_DETAILS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}") | ||
PR_ADDITIONS=$(echo $PR_DETAILS | jq '.additions') | ||
PR_DELETIONS=$(echo $PR_DETAILS | jq '.deletions') | ||
REPO_NAME=$(echo $PR_DETAILS | jq '.base.repo.full_name') | ||
# Send Slack notification | ||
curl -X POST -H 'Content-type: application/json' \ | ||
--data "{ | ||
\"text\": \"*Reminder:* Pull Request '${PR_TITLE}' is still in review, please take a look!\", | ||
\"blocks\": [ | ||
{ | ||
\"type\": \"section\", | ||
\"text\": { | ||
\"type\": \"mrkdwn\", | ||
\"text\": \":warning: *Reminder:* Pull Request <${PR_URL}|#${PR_NUMBER}> still needs a reviewer, please take a look!\" | ||
} | ||
}, | ||
{ | ||
\"type\": \"section\", | ||
\"text\": { | ||
\"type\": \"mrkdwn\", | ||
\"text\": \":rocket: PR by ${PR_AUTHOR} needs a review: \`+${PR_ADDITIONS} -${PR_DELETIONS}\` <${PR_URL}|${REPO_NAME}#${PR_NUMBER}: ${PR_TITLE}>\" | ||
} | ||
} | ||
] | ||
}" \ | ||
$SLACK_WEBHOOK_URL | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Remove "Ready for review" label on PR approval | ||
|
||
on: | ||
pull_request_review: | ||
types: [submitted] | ||
|
||
jobs: | ||
remove-label-on-approval: | ||
if: github.event.review.state == 'approved' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Remove "Ready for review" label from PR | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const { data: pullRequest } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.payload.pull_request.number | ||
}); | ||
const labelToRemove = 'Ready for review'; | ||
const labels = pullRequest.labels.map(label => label.name); | ||
if (labels.includes(labelToRemove)) { | ||
await github.rest.issues.removeLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.payload.pull_request.number, | ||
name: labelToRemove | ||
}); | ||
console.log(`Removed label: ${labelToRemove}`); | ||
} else { | ||
console.log(`Label ${labelToRemove} not found on PR.`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
*.egg-info |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file defines which domain owns what parts of this repository. | ||
# | ||
# The syntax is the same as defined in | ||
# https://help.github.com/articles/about-codeowners/ | ||
# | ||
# Important Rules: | ||
# 1. The last matching pattern in this file takes precedence | ||
# | ||
# 2. Only domains (github team) own code, not individuals | ||
# see list at https://github.com/orgs/datarobot-oss/teams | ||
# | ||
# Default owners for everything in the repo. | ||
# Unless a later match takes precedence, these groups will be requested for | ||
# review when someone opens a pull request. | ||
* @datarobot-oss/applications-oss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
# flask-app-base | ||
Ready-to-use Flask application template for a rapid custom application development | ||
# Flask app base template | ||
|
||
## What's in this repository? | ||
In this repository you will find an empty Flask application base template to kickstart your custom app development. | ||
|
||
The Datarobot client is already set up for you to use, it uses the Application owners' API token by default. | ||
|
||
## How do I set it up? | ||
You can run the Flask app in DataRobot via Custom Applications or run the app directly locally. | ||
Custom Applications can be created either via the registry workshop or | ||
using [DRApps](https://github.com/datarobot/dr-apps/blob/main/README.md) | ||
|
||
Make sure to define the required variables for the app to talk to DataRobot. If you run the app from local or another | ||
environment than DataRobots Custom Applications you'll need to set the env variables. When this app is run via | ||
custom applications workshop they should be set automatically. | ||
|
||
```shell | ||
#start-app.sh | ||
export token="$DATAROBOT_API_TOKEN" # Your API token from DR developer tools page | ||
export endpoint="$DATAROBOT_ENDPOINT" # Example: https://app.datarobot.com/api/v2/ | ||
``` | ||
|
||
## How to add and use runtime parameters? | ||
Create a metadata.yaml file in your application source folder. Here is an example of a DEPLOYMENT_ID: | ||
```yaml | ||
runtimeParameterDefinitions: | ||
- fieldName: DEPLOYMENT_ID | ||
type: string | ||
``` | ||
Once this file is part of your Application source in DataRobot, it will display the new runtime parameter(s) as part of the | ||
app configuration. | ||
To use the parameters we recommend to add them via `start-app.sh`, add this conditional export before `gunicorn` starts: | ||
```shell | ||
if [ -n "$MLOPS_RUNTIME_PARAM_DEPLOYMENT_ID" ]; then | ||
export deployment_id="$MLOPS_RUNTIME_PARAM_DEPLOYMENT_ID" | ||
fi | ||
``` | ||
|
||
Now you can use `os.getenv("deployment_id")` within your application code. | ||
|
||
## How do I add more pages? | ||
In the `./src/templates` directory you will find a sample index page. You can add additional HTML templates here, and | ||
call them by adding new routes in the `flask_app.py` like this: | ||
```python | ||
@flask_app.route("/new-page") | ||
def index_route(): | ||
return render_template("new-page.html", message="Hello World!") | ||
``` | ||
|
||
Contents of new-page.html: | ||
```html | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Flask Template</title> | ||
</head> | ||
<body> | ||
<h1>{{ message }}</h1> | ||
</body> | ||
</html> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import logging | ||
import os | ||
|
||
from datarobot import Client | ||
from datarobot.client import set_client | ||
from flask import Flask, render_template | ||
from werkzeug.middleware.proxy_fix import ProxyFix | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# Setup DR client | ||
DR_TOKEN = os.getenv("token") | ||
DR_ENDPOINT = os.getenv("endpoint") | ||
set_client(Client(token=DR_TOKEN, endpoint=DR_ENDPOINT)) | ||
|
||
base_dir = os.path.abspath(os.path.dirname(__file__)) | ||
flask_app = Flask(__name__, template_folder=os.path.join(base_dir, 'templates')) | ||
flask_app.wsgi_app = ProxyFix(flask_app.wsgi_app, x_prefix=1) | ||
|
||
@flask_app.route("/") | ||
def index_route(): | ||
return render_template("index.html", message="Hello from Flask") | ||
|
||
if __name__ == "__main__": | ||
flask_app.run(host="0.0.0.0", debug=False, port=8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
aiohttp>=3.10.6 | ||
flask>=3.0.3 | ||
gunicorn>=23.0.0 | ||
datarobot>=3.5.2 |
Oops, something went wrong.