Skip to content

Commit

Permalink
Merge branch 'master' into Add-Chinese-Translation-for-docs-tutorial-…
Browse files Browse the repository at this point in the history
…security-first-steps.md
  • Loading branch information
tiangolo committed Aug 18, 2022
2 parents 61de13d + a792281 commit 2a9f100
Show file tree
Hide file tree
Showing 731 changed files with 34,928 additions and 3,453 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ body:
Thanks for your interest in FastAPI! 🚀
Please follow these instructions, fill every question, and do every step. 🙏
I'm asking this because answering questions and solving problems in GitHub issues is what consumes most of the time.
I end up not being able to add new features, fix bugs, review pull requests, etc. as fast as I wish because I have to spend too much time handling issues.
All that, on top of all the incredible help provided by a bunch of community members, the [FastAPI Experts](https://fastapi.tiangolo.com/fastapi-people/#experts), that give a lot of their time to come here and help others.
That's a lot of work they are doing, but if more FastAPI users came to help others like them just a little bit more, it would be much less effort for them (and you and me 😅).
By asking questions in a structured way (following this) it will be much easier to help you.
And there's a high chance that you will find the solution along the way and you won't even have to submit it and wait for an answer. 😎
As there are too many issues with questions, I'll have to close the incomplete ones. That will allow me (and others) to focus on helping people like you that follow the whole process and help us help you. 🤓
Expand Down Expand Up @@ -50,7 +50,7 @@ body:
label: Commit to Help
description: |
After submitting this, I commit to one of:
* Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
* I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
* Implement a Pull Request for a confirmed bug.
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ body:
Thanks for your interest in FastAPI! 🚀
Please follow these instructions, fill every question, and do every step. 🙏
I'm asking this because answering questions and solving problems in GitHub issues is what consumes most of the time.
I end up not being able to add new features, fix bugs, review pull requests, etc. as fast as I wish because I have to spend too much time handling issues.
All that, on top of all the incredible help provided by a bunch of community members, the [FastAPI Experts](https://fastapi.tiangolo.com/fastapi-people/#experts), that give a lot of their time to come here and help others.
That's a lot of work they are doing, but if more FastAPI users came to help others like them just a little bit more, it would be much less effort for them (and you and me 😅).
By asking questions in a structured way (following this) it will be much easier to help you.
And there's a high chance that you will find the solution along the way and you won't even have to submit it and wait for an answer. 😎
As there are too many issues with questions, I'll have to close the incomplete ones. That will allow me (and others) to focus on helping people like you that follow the whole process and help us help you. 🤓
Expand Down Expand Up @@ -50,7 +50,7 @@ body:
label: Commit to Help
description: |
After submitting this, I commit to one of:
* Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
* I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
* Implement a Pull Request for a confirmed bug.
Expand Down
10 changes: 4 additions & 6 deletions .github/actions/comment-docs-preview-in-pr/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys
from pathlib import Path
from typing import Optional
from typing import Union

import httpx
from github import Github
Expand All @@ -14,7 +14,7 @@
class Settings(BaseSettings):
github_repository: str
github_event_path: Path
github_event_name: Optional[str] = None
github_event_name: Union[str, None] = None
input_token: SecretStr
input_deploy_url: str

Expand Down Expand Up @@ -42,15 +42,13 @@ class PartialGithubEvent(BaseModel):
except ValidationError as e:
logging.error(f"Error parsing event file: {e.errors()}")
sys.exit(0)
use_pr: Optional[PullRequest] = None
use_pr: Union[PullRequest, None] = None
for pr in repo.get_pulls():
if pr.head.sha == event.workflow_run.head_commit.id:
use_pr = pr
break
if not use_pr:
logging.error(
f"No PR found for hash: {event.workflow_run.head_commit.id}"
)
logging.error(f"No PR found for hash: {event.workflow_run.head_commit.id}")
sys.exit(0)
github_headers = {
"Authorization": f"token {settings.input_token.get_secret_value()}"
Expand Down
35 changes: 26 additions & 9 deletions .github/actions/notify-translations/app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import random
import time
from pathlib import Path
from typing import Dict, Optional
from typing import Dict, Union

import yaml
from github import Github
Expand All @@ -16,8 +18,8 @@ class Settings(BaseSettings):
github_repository: str
input_token: SecretStr
github_event_path: Path
github_event_name: Optional[str] = None
input_debug: Optional[bool] = False
github_event_name: Union[str, None] = None
input_debug: Union[bool, None] = False


class PartialGitHubEventIssue(BaseModel):
Expand Down Expand Up @@ -45,11 +47,14 @@ class PartialGitHubEvent(BaseModel):
github_event = PartialGitHubEvent.parse_raw(contents)
translations_map: Dict[str, int] = yaml.safe_load(translations_path.read_text())
logging.debug(f"Using translations map: {translations_map}")
sleep_time = random.random() * 10 # random number between 0 and 10 seconds
pr = repo.get_pull(github_event.pull_request.number)
logging.debug(f"Processing PR: {pr.number}")
logging.debug(
f"Processing PR: {pr.number}, with anti-race condition sleep time: {sleep_time}"
)
if pr.state == "open":
logging.debug(f"PR is open: {pr.number}")
label_strs = set([label.name for label in pr.get_labels()])
label_strs = {label.name for label in pr.get_labels()}
if lang_all_label in label_strs and awaiting_label in label_strs:
logging.info(
f"This PR seems to be a language translation and awaiting reviews: {pr.number}"
Expand All @@ -67,19 +72,31 @@ class PartialGitHubEvent(BaseModel):
for lang in langs:
if lang in translations_map:
num = translations_map[lang]
logging.info(f"Found a translation issue for language: {lang} in issue: {num}")
logging.info(
f"Found a translation issue for language: {lang} in issue: {num}"
)
issue = repo.get_issue(num)
message = f"Good news everyone! 😉 There's a new translation PR to be reviewed: #{pr.number} 🎉"
already_notified = False
logging.info(f"Checking current comments in issue: {num} to see if already notified about this PR: {pr.number}")
time.sleep(sleep_time)
logging.info(
f"Sleeping for {sleep_time} seconds to avoid race conditions and multiple comments"
)
logging.info(
f"Checking current comments in issue: {num} to see if already notified about this PR: {pr.number}"
)
for comment in issue.get_comments():
if message in comment.body:
already_notified = True
if not already_notified:
logging.info(f"Writing comment in issue: {num} about PR: {pr.number}")
logging.info(
f"Writing comment in issue: {num} about PR: {pr.number}"
)
issue.create_comment(message)
else:
logging.info(f"Issue: {num} was already notified of PR: {pr.number}")
logging.info(
f"Issue: {num} was already notified of PR: {pr.number}"
)
else:
logging.info(
f"Changing labels in a closed PR doesn't trigger comments, PR: {pr.number}"
Expand Down
7 changes: 6 additions & 1 deletion .github/actions/notify-translations/app/translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ uk: 1748
tr: 1892
fr: 1972
ko: 2017
sq: 2041
fa: 2041
pl: 3169
de: 3716
id: 3717
az: 3994
nl: 4701
uz: 4883
sv: 5146
he: 5157
39 changes: 24 additions & 15 deletions .github/actions/people/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import Counter, defaultdict
from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Container, DefaultDict, Dict, List, Optional, Set
from typing import Container, DefaultDict, Dict, List, Set, Union

import httpx
import yaml
Expand All @@ -14,7 +14,7 @@
github_graphql_url = "https://api.github.com/graphql"

issues_query = """
query Q($after: String) {
query Q($after: String) {
repository(name: "fastapi", owner: "tiangolo") {
issues(first: 100, after: $after) {
edges {
Expand Down Expand Up @@ -47,7 +47,7 @@
"""

prs_query = """
query Q($after: String) {
query Q($after: String) {
repository(name: "fastapi", owner: "tiangolo") {
pullRequests(first: 100, after: $after) {
edges {
Expand Down Expand Up @@ -133,7 +133,7 @@ class Author(BaseModel):

class CommentsNode(BaseModel):
createdAt: datetime
author: Optional[Author] = None
author: Union[Author, None] = None


class Comments(BaseModel):
Expand All @@ -142,7 +142,7 @@ class Comments(BaseModel):

class IssuesNode(BaseModel):
number: int
author: Optional[Author] = None
author: Union[Author, None] = None
title: str
createdAt: datetime
state: str
Expand Down Expand Up @@ -179,7 +179,7 @@ class Labels(BaseModel):


class ReviewNode(BaseModel):
author: Optional[Author] = None
author: Union[Author, None] = None
state: str


Expand All @@ -190,7 +190,7 @@ class Reviews(BaseModel):
class PullRequestNode(BaseModel):
number: int
labels: Labels
author: Optional[Author] = None
author: Union[Author, None] = None
title: str
createdAt: datetime
state: str
Expand Down Expand Up @@ -263,7 +263,7 @@ class Settings(BaseSettings):


def get_graphql_response(
*, settings: Settings, query: str, after: Optional[str] = None
*, settings: Settings, query: str, after: Union[str, None] = None
):
headers = {"Authorization": f"token {settings.input_token.get_secret_value()}"}
variables = {"after": after}
Expand All @@ -280,19 +280,19 @@ def get_graphql_response(
return data


def get_graphql_issue_edges(*, settings: Settings, after: Optional[str] = None):
def get_graphql_issue_edges(*, settings: Settings, after: Union[str, None] = None):
data = get_graphql_response(settings=settings, query=issues_query, after=after)
graphql_response = IssuesResponse.parse_obj(data)
return graphql_response.data.repository.issues.edges


def get_graphql_pr_edges(*, settings: Settings, after: Optional[str] = None):
def get_graphql_pr_edges(*, settings: Settings, after: Union[str, None] = None):
data = get_graphql_response(settings=settings, query=prs_query, after=after)
graphql_response = PRsResponse.parse_obj(data)
return graphql_response.data.repository.pullRequests.edges


def get_graphql_sponsor_edges(*, settings: Settings, after: Optional[str] = None):
def get_graphql_sponsor_edges(*, settings: Settings, after: Union[str, None] = None):
data = get_graphql_response(settings=settings, query=sponsors_query, after=after)
graphql_response = SponsorsResponse.parse_obj(data)
return graphql_response.data.user.sponsorshipsAsMaintainer.edges
Expand Down Expand Up @@ -501,9 +501,16 @@ def get_top_users(
github_sponsors_path = Path("./docs/en/data/github_sponsors.yml")
people_old_content = people_path.read_text(encoding="utf-8")
github_sponsors_old_content = github_sponsors_path.read_text(encoding="utf-8")
new_people_content = yaml.dump(people, sort_keys=False, width=200, allow_unicode=True)
new_github_sponsors_content = yaml.dump(github_sponsors, sort_keys=False, width=200, allow_unicode=True)
if people_old_content == new_people_content and github_sponsors_old_content == new_github_sponsors_content:
new_people_content = yaml.dump(
people, sort_keys=False, width=200, allow_unicode=True
)
new_github_sponsors_content = yaml.dump(
github_sponsors, sort_keys=False, width=200, allow_unicode=True
)
if (
people_old_content == new_people_content
and github_sponsors_old_content == new_github_sponsors_content
):
logging.info("The FastAPI People data hasn't changed, finishing.")
sys.exit(0)
people_path.write_text(new_people_content, encoding="utf-8")
Expand All @@ -517,7 +524,9 @@ def get_top_users(
logging.info(f"Creating a new branch {branch_name}")
subprocess.run(["git", "checkout", "-b", branch_name], check=True)
logging.info("Adding updated file")
subprocess.run(["git", "add", str(people_path)], check=True)
subprocess.run(
["git", "add", str(people_path), str(github_sponsors_path)], check=True
)
logging.info("Committing updated file")
message = "👥 Update FastAPI People"
result = subprocess.run(["git", "commit", "-m", message], check=True)
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/watch-previews/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from datetime import datetime
from pathlib import Path
from typing import List, Optional
from typing import List, Union

import httpx
from github import Github
Expand All @@ -16,7 +16,7 @@ class Settings(BaseSettings):
input_token: SecretStr
github_repository: str
github_event_path: Path
github_event_name: Optional[str] = None
github_event_name: Union[str, None] = None


class Artifact(BaseModel):
Expand Down Expand Up @@ -74,7 +74,7 @@ def get_message(commit: str) -> str:
logging.info(f"Docs preview was notified: {notified}")
if not notified:
artifact_name = f"docs-zip-{commit}"
use_artifact: Optional[Artifact] = None
use_artifact: Union[Artifact, None] = None
for artifact in artifacts_response.artifacts:
if artifact.name == artifact_name:
use_artifact = artifact
Expand Down
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix:
# Python
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix:
Loading

0 comments on commit 2a9f100

Please sign in to comment.