@@ -3059,57 +3059,56 @@ export const make = Effect.gen(function* () {
30593059 } ) ;
30603060 } ,
30613061
3062- uploadAttachment : ( input ) =>
3063- Effect . gen ( function * ( ) {
3064- const host = input . host . toLowerCase ( ) ;
3065- if ( host !== "github.com" && ! host . endsWith ( ".ghe.com" ) )
3066- return yield * readError (
3067- input . cwd ,
3068- "uploadAttachment" ,
3069- new Error (
3070- "Local attachments are supported on GitHub.com and GitHub Enterprise Cloud. Paste a hosted link for this host." ,
3071- ) ,
3072- ) ;
3073- const repository = yield * api . rest ( {
3074- host,
3075- operation : "uploadAttachment" ,
3076- path : `repos/${ input . repository } ` ,
3077- } ) ;
3078- const decoded = yield * decodeAttachmentRepository ( repository . body ) . pipe (
3079- Effect . mapError ( ( cause ) => readError ( input . cwd , "uploadAttachment" , cause ) ) ,
3062+ uploadAttachment : Effect . fn ( "GitHubPullRequestApi.uploadAttachment" ) ( function * ( input ) {
3063+ const host = input . host . toLowerCase ( ) ;
3064+ if ( host !== "github.com" && ! host . endsWith ( ".ghe.com" ) )
3065+ return yield * readError (
3066+ input . cwd ,
3067+ "uploadAttachment" ,
3068+ new Error (
3069+ "Local attachments are supported on GitHub.com and GitHub Enterprise Cloud. Paste a hosted link for this host." ,
3070+ ) ,
30803071 ) ;
3081- const result = yield * api . rest ( {
3082- host,
3083- operation : "uploadAttachment" ,
3084- method : "POST" ,
3085- path : "user-attachments/assets" ,
3086- timeout : "2 minutes" ,
3087- upload : {
3088- repositoryId : decoded . id ,
3089- name : input . name ,
3090- mimeType : input . mimeType ,
3091- sizeBytes : input . sizeBytes ,
3092- stream : fileSystem . stream ( input . path ) ,
3093- } ,
3094- } ) ;
3095- const asset = yield * decodeAttachmentAsset ( result . body ) . pipe (
3096- Effect . mapError ( ( cause ) => readError ( input . cwd , "uploadAttachment" , cause ) ) ,
3072+ const repository = yield * api . rest ( {
3073+ host,
3074+ operation : "uploadAttachment" ,
3075+ path : `repos/${ input . repository } ` ,
3076+ } ) ;
3077+ const decoded = yield * decodeAttachmentRepository ( repository . body ) . pipe (
3078+ Effect . mapError ( ( cause ) => readError ( input . cwd , "uploadAttachment" , cause ) ) ,
3079+ ) ;
3080+ const result = yield * api . rest ( {
3081+ host,
3082+ operation : "uploadAttachment" ,
3083+ method : "POST" ,
3084+ path : "user-attachments/assets" ,
3085+ timeout : "2 minutes" ,
3086+ upload : {
3087+ repositoryId : decoded . id ,
3088+ name : input . name ,
3089+ mimeType : input . mimeType ,
3090+ sizeBytes : input . sizeBytes ,
3091+ stream : fileSystem . stream ( input . path ) ,
3092+ } ,
3093+ } ) ;
3094+ const asset = yield * decodeAttachmentAsset ( result . body ) . pipe (
3095+ Effect . mapError ( ( cause ) => readError ( input . cwd , "uploadAttachment" , cause ) ) ,
3096+ ) ;
3097+ const url = yield * Effect . try ( {
3098+ try : ( ) => new URL ( asset . url ) ,
3099+ catch : ( cause ) => readError ( input . cwd , "uploadAttachment" , cause ) ,
3100+ } ) ;
3101+ if (
3102+ url . protocol !== "https:" ||
3103+ ( url . hostname !== host && url . hostname !== `uploads.${ host } ` )
3104+ )
3105+ return yield * readError (
3106+ input . cwd ,
3107+ "uploadAttachment" ,
3108+ new Error ( "GitHub returned an invalid attachment URL." ) ,
30973109 ) ;
3098- const url = yield * Effect . try ( {
3099- try : ( ) => new URL ( asset . url ) ,
3100- catch : ( cause ) => readError ( input . cwd , "uploadAttachment" , cause ) ,
3101- } ) ;
3102- if (
3103- url . protocol !== "https:" ||
3104- ( url . hostname !== host && url . hostname !== `uploads.${ host } ` )
3105- )
3106- return yield * readError (
3107- input . cwd ,
3108- "uploadAttachment" ,
3109- new Error ( "GitHub returned an invalid attachment URL." ) ,
3110- ) ;
3111- return { url : asset . url } ;
3112- } ) ,
3110+ return { url : asset . url } ;
3111+ } ) ,
31133112
31143113 commentOnPullRequest : ( input ) =>
31153114 pullRequestNodeId ( { ...input , operation : "commentOnPullRequest" } ) . pipe (
0 commit comments