({
threadId,
integration,
}: {
threadId: string;
integration: channelsIntegration;
})
| 129 | } |
| 130 | |
| 131 | async 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, |
no test coverage detected