eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.56 kB
JavaScript
import{callGitHubApi,createGitHubIssueComment,createGitHubReaction,createGitHubReviewCommentReply}from"#public/channels/github/api.js";function buildGitHubBinding(e){let{config:t,state:n}=e,r={fullName:`${n.owner}/${n.repo}`,id:n.repositoryId,name:n.repo,owner:n.owner,private:!1},i=n.installationId??void 0;return{github:{installationId:i,repository:r,request(e){return callGitHubApi({api:t.api,body:e.body,credentials:t.credentials,installationId:i,method:e.method,path:e.path})}},thread:{kind:n.conversationKind,post(e){return n.conversationKind===`review_thread`?createGitHubReviewCommentReply({api:t.api,body:e,commentId:requiredStateNumber(n.reviewThreadRootCommentId??n.reviewCommentId,`reviewThreadRootCommentId`),credentials:t.credentials,installationId:i,owner:n.owner,pullRequestNumber:requiredStateNumber(n.pullRequestNumber,`pullRequestNumber`),repo:n.repo}):createGitHubIssueComment({api:t.api,body:e,credentials:t.credentials,installationId:i,issueNumber:requiredStateNumber(n.issueNumber??n.pullRequestNumber,`issueNumber`),owner:n.owner,repo:n.repo})},async react(e){let r=n.conversationKind===`review_thread`?n.reviewCommentId:n.triggeringCommentId;r!==null&&await createGitHubReaction({api:t.api,commentId:r,content:e,credentials:t.credentials,installationId:i,owner:n.owner,repo:n.repo,subject:n.conversationKind===`review_thread`?`pull_request_review_comment`:`issue_comment`})}}}}function requiredStateNumber(e,t){if(typeof e==`number`&&Number.isFinite(e))return e;throw Error(`githubChannel: missing ${t}.`)}export{buildGitHubBinding};