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
82 changes: 20 additions & 62 deletions .github/workflows/feature-flag-mms-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
comment_body: ${{ steps.detect.outputs.comment_body }}
mms_pull_request_content: ${{ steps.detect.outputs.mms_pull_request_content }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
show-progress: false

- uses: actions/setup-node@v4
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24.15.0
cache: 'npm'
Expand Down Expand Up @@ -56,69 +56,27 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
show-progress: false

- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24.15.0
- name: Install npm@11.16.0
run: |
npm install -g npm@11.16.0

- name: Install Dependencies
run: |
npm ci -w compass-preferences-model --ignore-scripts

- name: Post or update comment on PR
uses: actions/github-script@v7
run: node packages/compass-preferences-model/scripts/post-feature-flag-comment-on-pr.mts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_BODY: ${{ needs.detect-flags.outputs.comment_body }}
FLAGS_COUNT: ${{ needs.detect-flags.outputs.flags_count }}
with:
script: |
const marker = '<!-- feature-flag-mms-comment -->';
const outdatedMarker = '<!-- feature-flag-mms-comment-outdated -->';
const flagsCount = process.env.FLAGS_COUNT;
const hasFlags = flagsCount !== '' && flagsCount !== '0';

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const existing = comments.find(c => c.body.includes(marker));

// No new feature flags and no existing comment: nothing to do.
if (!existing && !hasFlags) {
return;
}

// New flag and no existing comment: create a new comment.
if (hasFlags && !existing) {
return await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: marker + '\n' + process.env.COMMENT_BODY,
});
}

// New flag and existing comment: update the existing comment.
if (hasFlags && existing) {
return await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: marker + '\n' + process.env.COMMENT_BODY,
});
}

// No flag, but existing comment: mark the comment as outdated.
if (!hasFlags && existing && !existing.body.includes(outdatedMarker)) {
const previous = existing.body
.replace(marker, '')
.trim();
const body = marker + '\n' + outdatedMarker + '\n' +
'> [!NOTE]\n' +
'> The new feature flag(s) originally detected in this PR are no longer ' +
'present in the latest commits, so this notice no longer applies.\n\n' +
'<details><summary>Previous message</summary>\n\n' +
previous + '\n\n</details>';
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
}

create-mms-pr:
name: Create MMS PR
Expand All @@ -139,7 +97,7 @@ jobs:
repositories: mms

- name: Checkout MMS
uses: actions/checkout@v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: 10gen/mms
token: ${{ steps.app-token.outputs.token }}
Expand Down
Loading
Loading