66from subprocess import call
77import dropbox
88
9+
910def main (url , dropbox_token ):
1011 call (["git" , "config" , "--global" , "--add" , "safe.directory" , "/github/workspace" ])
1112 # Take a screenshot using the snapsht CLI tool
@@ -19,44 +20,60 @@ def main(url, dropbox_token):
1920 # Authenticate Dropbox and upload the screenshot
2021 dbx = dropbox .Dropbox (dropbox_token )
2122 with open ("screenshot.png" , "rb" ) as image_file :
22- meta = dbx .files_upload (image_file .read (), f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png" , mode = dropbox .files .WriteMode ("overwrite" ))
23-
23+ meta = dbx .files_upload (
24+ image_file .read (),
25+ f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png" ,
26+ mode = dropbox .files .WriteMode ("overwrite" ),
27+ )
28+
2429 # Check the account type
2530 account = dbx .users_get_current_account ()
2631 is_team_account = isinstance (account .account_type , dropbox .users .Team )
2732
2833 if not is_team_account :
29- print ("The dropbox token does not belong to a teams account and image links will be public." )
34+ print (
35+ "The dropbox token does not belong to a teams account and image links will be public."
36+ )
3037 # Prepare the shared link settings based on the account type
3138 if is_team_account :
32- shared_link_settings = dropbox .sharing .SharedLinkSettings (requested_visibility = dropbox .sharing .RequestedVisibility .team_only )
39+ shared_link_settings = dropbox .sharing .SharedLinkSettings (
40+ requested_visibility = dropbox .sharing .RequestedVisibility .team_only
41+ )
3342 else :
3443 shared_link_settings = None
3544
3645 # Try to create a shared link, and if it already exists, use the existing link
3746 try :
3847 if shared_link_settings :
39- shared_link_metadata = dbx .sharing_create_shared_link_with_settings (f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png" , shared_link_settings )
48+ shared_link_metadata = dbx .sharing_create_shared_link_with_settings (
49+ f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png" ,
50+ shared_link_settings ,
51+ )
4052 else :
41- shared_link_metadata = dbx .sharing_create_shared_link_with_settings (f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png" )
53+ shared_link_metadata = dbx .sharing_create_shared_link_with_settings (
54+ f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png"
55+ )
4256 shared_link = shared_link_metadata .url
43- dropbox_link = shared_link .replace (' ?dl=0' , ' ?dl=1' )
57+ dropbox_link = shared_link .replace (" ?dl=0" , " ?dl=1" )
4458 except dropbox .exceptions .ApiError as e :
4559 if e .error .is_shared_link_already_exists ():
46- shared_link_metadata = dbx .sharing_get_shared_links (f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png" )
60+ shared_link_metadata = dbx .sharing_get_shared_links (
61+ f"/screenshots/{ os .environ ['GITHUB_REPOSITORY' ]} _PR_{ pr_number } .png"
62+ )
4763 shared_link = shared_link_metadata .links [0 ].url
48- dropbox_link = shared_link .replace (' ?dl=0' , ' ?dl=1' )
64+ dropbox_link = shared_link .replace (" ?dl=0" , " ?dl=1" )
4965 else :
5066 raise
5167
5268 comment_body = f"Screenshot uploaded to Dropbox: [View Screenshot]({ dropbox_link } )"
5369 call (["gh" , "pr" , "comment" , str (pr_number ), "--body" , comment_body ])
5470
71+
5572if __name__ == "__main__" :
5673 if len (sys .argv ) != 3 :
5774 print ("Usage: entrypoint.py <url> <dropbox_token>" )
5875 sys .exit (1 )
59-
76+
6077 url = sys .argv [1 ]
6178 dropbox_token = sys .argv [2 ]
62- main (url , dropbox_token )
79+ main (url , dropbox_token )
0 commit comments