diff --git a/src/github/junie/prepare-junie.ts b/src/github/junie/prepare-junie.ts index 502185d2..ca85d9d3 100644 --- a/src/github/junie/prepare-junie.ts +++ b/src/github/junie/prepare-junie.ts @@ -68,7 +68,8 @@ export async function initializeJunieExecution({ try { console.log('Youtrack Payload: ', JSON.stringify(context.payload, null, 2)); const client = getYouTrackClient(context.payload.youtrackBaseUrl); - const commentId = await client.addComment(context.payload.issueId, INIT_COMMENT_BODY); + // Restricted to jetbrains-team only: this is an internal status update, not meant for external reporters + const commentId = await client.addComment(context.payload.issueId, INIT_COMMENT_BODY, true); if (commentId) { core.setOutput(OUTPUT_VARS.YOUTRACK_INIT_COMMENT_ID, commentId); } diff --git a/src/github/youtrack/client.ts b/src/github/youtrack/client.ts index 5c2fe307..d6722ed1 100644 --- a/src/github/youtrack/client.ts +++ b/src/github/youtrack/client.ts @@ -3,6 +3,12 @@ /** * YouTrack API client wrapper */ + +// Id of the "jetbrains-team" YouTrack group. Hardcoded because the dynamic name->id +// lookup via /api/groups never resolves this group, regardless of the token's +// permissions - it is simply never returned by that listing endpoint. +const JETBRAINS_TEAM_GROUP_ID = "10-3"; + class YouTrackClient { private readonly token: string; @@ -33,17 +39,25 @@ class YouTrackClient { * * @param issueId - YouTrack issue ID (e.g., PROJ-123) * @param text - Comment text in Markdown + * @param restrictToJetBrainsTeam - If true, the comment is only visible to the jetbrains-team group * @returns comment ID if successful, null otherwise */ - async addComment(issueId: string, text: string): Promise { + async addComment(issueId: string, text: string, restrictToJetBrainsTeam = false): Promise { try { console.log(`Adding comment to YouTrack issue ${issueId}`); const url = `${this.baseUrl}/api/issues/${issueId}/comments?fields=id`; + const body: Record = { text }; + if (restrictToJetBrainsTeam) { + body.visibility = { + '$type': 'LimitedVisibility', + permittedGroups: [{ id: JETBRAINS_TEAM_GROUP_ID }], + }; + } const response = await fetch(url, { method: 'POST', headers: this.authHeaders, - body: JSON.stringify({ text }), + body: JSON.stringify(body), }); if (!response.ok) {