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

Function processNewThread

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

Source from the content-addressed store, hash-verified

129}
130
131async function processNewThread({
132 threadId,
133 integration,
134}: {
135 threadId: string;
136 integration: channelsIntegration;
137}) {
138 const thread = await linenSdk.getThread({
139 channelId: integration.channelId,
140 threadId,
141 });
142
143 if (!thread) {
144 return 'ThreadNotFound';
145 }
146
147 if (!thread.messages.length) {
148 return 'ThreadNotFound';
149 }
150
151 if (thread.externalThreadId) {
152 return 'skip two-way sync due thread is not from linen';
153 }
154
155 const ownerRepo = integration.data as any;
156
157 const data: threadCreateType = {
158 body: thread.messages[0].body,
159 integrationId: Number(integration.externalId),
160 owner: ownerRepo.owner,
161 repo: ownerRepo.repo,
162 channelId: integration.channelId,
163 ...(thread.title && { title: thread.title }),
164 ...(thread.messages[0].author?.displayName && {
165 displayName: thread.messages[0].author?.displayName,
166 }),
167 };
168
169 const octokit = await githubApp.getInstallationOctokit(data.integrationId);
170
171 const newThread = await octokit.rest.issues.create({
172 title: data.title || data.body,
173 body: _buildMessage(data.body, data.displayName),
174 owner: data.owner,
175 repo: data.repo,
176 });
177
178 const externalId = Serializer.buildExternalId(
179 data.channelId,
180 data.owner,
181 data.repo,
182 newThread.data.number
183 );
184
185 await linenSdk.updateThread({
186 externalThreadId: externalId,
187 threadId,
188 channelId: data.channelId,

Callers 1

processGithubIntegrationFunction · 0.70

Calls 5

_buildMessageFunction · 0.85
getThreadMethod · 0.80
buildExternalIdMethod · 0.80
updateThreadMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected