MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / processThreadUpdate

Function processThreadUpdate

packages/integration-github/src/outbound.ts:194–262  ·  view source on GitHub ↗
({
  threadId,
  integration,
  event,
}: {
  threadId: string;
  integration: channelsIntegration;
  event: TwoWaySyncEvent;
})

Source from the content-addressed store, hash-verified

192}
193
194async function processThreadUpdate({
195 threadId,
196 integration,
197 event,
198}: {
199 threadId: string;
200 integration: channelsIntegration;
201 event: TwoWaySyncEvent;
202}) {
203 const thread = await linenSdk.getThread({
204 channelId: integration.channelId,
205 threadId,
206 });
207
208 if (!thread) {
209 return 'ThreadNotFound';
210 }
211
212 if (!thread.messages.length) {
213 return 'ThreadNotFound';
214 }
215
216 if (!thread.externalThreadId) {
217 return 'missing thread external id';
218 }
219
220 const data: threadUpdateSchema = {
221 body: thread.messages[0].body,
222 integrationId: Number(integration.externalId),
223 externalThreadId: thread.externalThreadId,
224 ...(!!thread.title && { title: thread.title }),
225 ...(!!thread.messages[0].author?.displayName && {
226 displayName: thread.messages[0].author?.displayName,
227 }),
228 };
229
230 const octokit = await githubApp.getInstallationOctokit(data.integrationId);
231 const { issueNumber, owner, repo } = Serializer.extractDataFromExternalId(
232 data.externalThreadId
233 );
234
235 if (event === 'threadClosed') {
236 await octokit.rest.issues.update({
237 issue_number: issueNumber,
238 state: 'closed',
239 owner,
240 repo,
241 });
242 return `issue closed: ${issueNumber}`;
243 } else if (event === 'threadReopened') {
244 await octokit.rest.issues.update({
245 issue_number: issueNumber,
246 state: 'open',
247 owner,
248 repo,
249 });
250 return `issue reopened: ${issueNumber}`;
251 } else if (event === 'threadUpdated') {

Callers 1

processGithubIntegrationFunction · 0.70

Calls 3

getThreadMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected