Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,65 @@ jest.mock('../../config', () => ({
}
}))

import { PullRequestSyncManager } from '../pullrequests'
import {
buildPullRequestTicketBacklinkBody,
extractTrackerIdentifiersFromPullRequest,
getPullRequestTicketLinkMarker,
isPullRequestTicketTargetIssue,
PullRequestSyncManager
} from '../pullrequests'
/* eslint-enable import/first */

describe('PullRequestSyncManager', () => {
describe('extractTrackerIdentifiersFromPullRequest', () => {
it('extracts unique tracker identifiers from title and body in encounter order', () => {
const result = extractTrackerIdentifiersFromPullRequest(
'fix: ABC-123 settle refunds',
'Refs abc-123, DEF-4, and XYZ-389.'
)

expect(result).toEqual(['ABC-123', 'DEF-4', 'XYZ-389'])
})

it('ignores text without tracker-like identifiers', () => {
expect(extractTrackerIdentifiersFromPullRequest('release v0.7.423', 'No linked ticket')).toEqual([])
})
})

describe('buildPullRequestTicketBacklinkBody', () => {
it('includes a stable marker and the Huly issue link', () => {
const repository = {
_id: 'repo-id',
nodeId: 'repo-node',
name: 'svc'
} as any
const marker = getPullRequestTicketLinkMarker(repository, 42, 'ABC-123')
const body = buildPullRequestTicketBacklinkBody(
'ABC-123',
'https://example.com/workbench/workspace/tracker/ABC-123',
marker
)

expect(body).toContain('<!-- huly-pr-ticket-link:repo-node:42:ABC-123 -->')
expect(body).toContain('https://example.com/workbench/workspace/tracker/ABC-123')
expect(body).toContain('Huly&reg;: ABC-123')
})
})

describe('isPullRequestTicketTargetIssue', () => {
it('does not treat a missing issue as a ticket target', () => {
expect(isPullRequestTicketTargetIssue()).toBe(false)
})

it('treats ordinary tracker issues as ticket targets', () => {
expect(isPullRequestTicketTargetIssue({ _class: 'tracker:class:Issue' } as any)).toBe(true)
})

it('does not treat GitHub pull request mirrors as ticket targets', () => {
expect(isPullRequestTicketTargetIssue({ _class: 'github:class:GithubPullRequest' } as any)).toBe(false)
})
})

describe('getReviewers', () => {
let manager: PullRequestSyncManager
let mockProvider: any
Expand Down
37 changes: 21 additions & 16 deletions services/github/pod-github/src/sync/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,24 @@ export class CommentSyncManager implements DocSyncManager {

if (Object.keys(platformUpdate).length > 0) {
// Check and update body with external
const okit = ensureRESTOctokit(
(await this.provider.getOctokit(ctx, existing.modifiedBy)) ?? container.container.octokit,
container
)
const mdown = await this.provider.getMarkdown(existingComment.message)
if (mdown.trim().length > 0) {
await okit.rest.issues.updateComment({
owner: repository.owner?.login as string,
repo: repository.name,
issue_number: parent.githubNumber,
comment_id: comment.id,
body: mdown,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
if (isGHWriteAllowed()) {
const okit = ensureRESTOctokit(
(await this.provider.getOctokit(ctx, existing.modifiedBy)) ?? container.container.octokit,
container
)
const mdown = await this.provider.getMarkdown(existingComment.message)
if (mdown.trim().length > 0) {
await okit.rest.issues.updateComment({
owner: repository.owner?.login as string,
repo: repository.name,
issue_number: parent.githubNumber,
comment_id: comment.id,
body: mdown,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
}
}
}
if (Object.keys(update).length > 0) {
Expand Down Expand Up @@ -436,6 +438,9 @@ export class CommentSyncManager implements DocSyncManager {
if (parent === undefined) {
return {}
}
if (!isGHWriteAllowed()) {
return { needSync: githubSyncVersion }
}
const chatMessage = existing as ChatMessage
const okit = ensureRESTOctokit(
(await this.provider.getOctokit(ctx, chatMessage.modifiedBy)) ?? container.container.octokit,
Expand Down
Loading