File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM python: 3
2
+
3
+ RUN pip install requests
4
+
5
+ COPY publish.py /publish.py
6
+
7
+ # TODO: unsure if additional logic should be handled in entrypoint.sh or if we should just do everything inside of python
8
+ COPY entrypoint.sh /entrypoint.sh
9
+
10
+ ENTRYPOINT ["/entrypoint.sh" ]
Original file line number Diff line number Diff line change
1
+ name : ' Publish Dev.to Article'
2
+ description : ' Publish article to Dev.to blogging platform'
3
+ runs :
4
+ using : ' docker'
5
+ image : ' Dockerfile'
Original file line number Diff line number Diff line change
1
+ #import required libraries
2
+ import requests , re , os , sys
3
+
4
+ API_ENDPOINT = "https://dev.to/api/articles"
5
+
6
+ PR = os .getenv ('PR_LIST_FILE' )
7
+ API_KEY = os .getenv ('DEV_TO_TOKEN' )
8
+ STATUS = 0
9
+
10
+ with open (PR , 'r' ) as files :
11
+ for line in files .readlines ():
12
+ if re .search ("^.*.md$" , line ):
13
+ with open (line .strip (),'r' ) as file :
14
+ data = file .read ().replace ('\n ' , '\\ n' )
15
+ json = '{"article":{"body_markdown": "' + data + '"}}'
16
+ headers = {'content-type' : 'application/json; charset=utf-8' , 'api-key' : API_KEY }
17
+ r = requests .post (url = API_ENDPOINT , data = json .encode ('utf-8' ), headers = headers )
18
+ if r .status_code != 201 :
19
+ print ("Unable to publish: " + line .strip ())
20
+ STATUS = 1
21
+ else :
22
+ print ("Published: " + line .strip ())
23
+
24
+ if STATUS != 0 :
25
+ print ("There were issues publishing one or more files. Please see logs above for more details" )
26
+ sys .exit (1 )
You can’t perform that action at this time.
0 commit comments