Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd47a16

Browse files
committed
resolve conflict
2 parentsd99da75 +de3db05 commitbd47a16

File tree

393 files changed

+5957
-2162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

393 files changed

+5957
-2162
lines changed

‎.env‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎.flake8‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 88
3+
select = C,E,F,W,B,B9
4+
ignore = E203, E501, W503
5+
exclude = __init__.py
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.7
2+
3+
RUN pip install httpx"pydantic==1.5.1"
4+
5+
COPY ./app /app
6+
7+
CMD ["python","/app/main.py"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name:"Get Artifact"
2+
description:"Get artifact, possibly uploaded by a PR, useful to deploy docs previews"
3+
author:"Sebastián Ramírez <tiangolo@gmail.com>"
4+
inputs:
5+
token:
6+
description:'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
7+
required:true
8+
name:
9+
description:'Artifact name'
10+
required:true
11+
path:
12+
description:'Where to store the artifact'
13+
required:true
14+
runs:
15+
using:'docker'
16+
image:'Dockerfile'
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
importlogging
2+
fromdatetimeimportdatetime
3+
frompathlibimportPath
4+
fromtypingimportList,Optional
5+
6+
importhttpx
7+
frompydanticimportBaseModel,BaseSettings,SecretStr
8+
9+
github_api="https://api.github.com"
10+
netlify_api="https://api.netlify.com"
11+
12+
13+
classSettings(BaseSettings):
14+
input_name:str
15+
input_token:SecretStr
16+
input_path:str
17+
github_repository:str
18+
github_event_path:Path
19+
github_event_name:Optional[str]=None
20+
21+
22+
classArtifact(BaseModel):
23+
id:int
24+
node_id:str
25+
name:str
26+
size_in_bytes:int
27+
url:str
28+
archive_download_url:str
29+
expired:bool
30+
created_at:datetime
31+
updated_at:datetime
32+
33+
34+
classArtifactResponse(BaseModel):
35+
total_count:int
36+
artifacts:List[Artifact]
37+
38+
39+
if__name__=="__main__":
40+
logging.basicConfig(level=logging.INFO)
41+
settings=Settings()
42+
logging.info(f"Using config:{settings.json()}")
43+
github_headers= {
44+
"Authorization":f"token{settings.input_token.get_secret_value()}"
45+
}
46+
response=httpx.get(
47+
f"{github_api}/repos/{settings.github_repository}/actions/artifacts",
48+
headers=github_headers,
49+
)
50+
data=response.json()
51+
artifacts_response=ArtifactResponse.parse_obj(data)
52+
use_artifact:Optional[Artifact]=None
53+
forartifactinartifacts_response.artifacts:
54+
ifartifact.name==settings.input_name:
55+
use_artifact=artifact
56+
break
57+
assertuse_artifact
58+
file_response=httpx.get(
59+
use_artifact.archive_download_url,headers=github_headers,timeout=30
60+
)
61+
zip_file=Path(settings.input_path)
62+
zip_file.write_bytes(file_response.content)
63+
logging.info("Finished")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.7
2+
3+
RUN pip install httpx PyGithub"pydantic==1.5.1"
4+
5+
COPY ./app /app
6+
7+
CMD ["python","/app/main.py"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name:"Watch docs previews in PRs"
2+
description:"Check PRs and trigger new docs deploys"
3+
author:"Sebastián Ramírez <tiangolo@gmail.com>"
4+
inputs:
5+
token:
6+
description:'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
7+
required:true
8+
runs:
9+
using:'docker'
10+
image:'Dockerfile'
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
importlogging
2+
fromdatetimeimportdatetime
3+
frompathlibimportPath
4+
fromtypingimportList,Optional
5+
6+
importhttpx
7+
fromgithubimportGithub
8+
fromgithub.NamedUserimportNamedUser
9+
frompydanticimportBaseModel,BaseSettings,SecretStr
10+
11+
github_api="https://api.github.com"
12+
netlify_api="https://api.netlify.com"
13+
14+
15+
classSettings(BaseSettings):
16+
input_token:SecretStr
17+
github_repository:str
18+
github_event_path:Path
19+
github_event_name:Optional[str]=None
20+
21+
22+
classArtifact(BaseModel):
23+
id:int
24+
node_id:str
25+
name:str
26+
size_in_bytes:int
27+
url:str
28+
archive_download_url:str
29+
expired:bool
30+
created_at:datetime
31+
updated_at:datetime
32+
33+
34+
classArtifactResponse(BaseModel):
35+
total_count:int
36+
artifacts:List[Artifact]
37+
38+
39+
defget_message(commit:str)->str:
40+
returnf"Docs preview for commit{commit} at"
41+
42+
43+
if__name__=="__main__":
44+
logging.basicConfig(level=logging.INFO)
45+
settings=Settings()
46+
logging.info(f"Using config:{settings.json()}")
47+
g=Github(settings.input_token.get_secret_value())
48+
repo=g.get_repo(settings.github_repository)
49+
owner:NamedUser=repo.owner
50+
headers= {"Authorization":f"token{settings.input_token.get_secret_value()}"}
51+
prs=list(repo.get_pulls(state="open"))
52+
response=httpx.get(
53+
f"{github_api}/repos/{settings.github_repository}/actions/artifacts",
54+
headers=headers,
55+
)
56+
data=response.json()
57+
artifacts_response=ArtifactResponse.parse_obj(data)
58+
forprinprs:
59+
logging.info("-----")
60+
logging.info(f"Processing PR #{pr.number}:{pr.title}")
61+
pr_comments=list(pr.get_issue_comments())
62+
pr_commits=list(pr.get_commits())
63+
last_commit=pr_commits[0]
64+
forpr_commitinpr_commits:
65+
ifpr_commit.commit.author.date>last_commit.commit.author.date:
66+
last_commit=pr_commit
67+
commit=last_commit.commit.sha
68+
logging.info(f"Last commit:{commit}")
69+
message=get_message(commit)
70+
notified=False
71+
forpr_commentinpr_comments:
72+
ifmessageinpr_comment.body:
73+
notified=True
74+
logging.info(f"Docs preview was notified:{notified}")
75+
ifnotnotified:
76+
artifact_name=f"docs-zip-{commit}"
77+
use_artifact:Optional[Artifact]=None
78+
forartifactinartifacts_response.artifacts:
79+
ifartifact.name==artifact_name:
80+
use_artifact=artifact
81+
break
82+
ifnotuse_artifact:
83+
logging.info("Artifact not available")
84+
else:
85+
logging.info(f"Existing artifact:{use_artifact.name}")
86+
response=httpx.post(
87+
"https://api.github.com/repos/tiangolo/fastapi/actions/workflows/preview-docs.yml/dispatches",
88+
headers=headers,
89+
json={
90+
"ref":"master",
91+
"inputs": {
92+
"pr":f"{pr.number}",
93+
"name":artifact_name,
94+
"commit":commit,
95+
},
96+
},
97+
)
98+
logging.info(
99+
f"Trigger sent, response status:{response.status_code} - content:{response.content}"
100+
)
101+
logging.info("Finished")
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name:Buildand Deploy to Netlify
1+
name:BuildDocs
22
on:
33
push:
44
pull_request:
@@ -7,6 +7,10 @@ jobs:
77
build:
88
runs-on:ubuntu-18.04
99
steps:
10+
-name:Dump GitHub context
11+
env:
12+
GITHUB_CONTEXT:${{ toJson(github) }}
13+
run:echo "$GITHUB_CONTEXT"
1014
-uses:actions/checkout@v2
1115
-name:Set up Python
1216
uses:actions/setup-python@v1
@@ -18,12 +22,21 @@ jobs:
1822
run:python3.7 -m flit install --extras doc
1923
-name:Build Docs
2024
run:python3.7 ./scripts/docs.py build-all
25+
-name:Zip docs
26+
if:github.event_name == 'pull_request'
27+
run:bash ./scripts/zip-docs.sh
28+
-uses:actions/upload-artifact@v2
29+
if:github.event_name == 'pull_request'
30+
with:
31+
name:docs-zip-${{ github.event.pull_request.head.sha }}
32+
path:./docs.zip
2133
-name:Deploy to Netlify
22-
uses:nwtgck/actions-netlify@v1.0.3
34+
uses:nwtgck/actions-netlify@v1.1.5
2335
with:
2436
publish-dir:'./site'
2537
production-branch:master
2638
github-token:${{ secrets.GITHUB_TOKEN }}
39+
enable-commit-comment:false
2740
env:
2841
NETLIFY_AUTH_TOKEN:${{ secrets.NETLIFY_AUTH_TOKEN }}
2942
NETLIFY_SITE_ID:${{ secrets.NETLIFY_SITE_ID }}

‎.github/workflows/pr-approvals.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name:Label approved pull requests
2+
on:pull_request_review
3+
jobs:
4+
labelWhenApproved:
5+
name:Label when approved
6+
runs-on:ubuntu-latest
7+
steps:
8+
-name:Label when approved
9+
uses:pullreminders/label-when-approved-action@v1.0.7
10+
env:
11+
APPROVALS:"2"
12+
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
13+
ADD_LABEL:"approved-2"
14+
REMOVE_LABEL:"awaiting%20review"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp