environments: nop mode reports no planned changes
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- github, javascript
調査の方向性
lib/plugins/environments.js の add()、update()、remove() と、issue で参照されている sync() の戻り経路から始めてください。issue に記載された失敗するテストを読み、その NopCommand の結果が lib/settings.js の Settings.appendToResults() に届くまでを追ってください。nop モードで、アクションメッセージが "Delete environment" の NopCommand をテストが確認できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Problem Description
What is actually happening
In nop (dry-run) mode, the environments plugin reports none of its planned changes, so dry-run PR checks never show environment changes. sync() resolves to [undefined].
add(), update() and remove() await this.nopifyRequest(...) but don't return the result, so resArray collects undefined. sync() also returns resArray without waiting for the pending changes. Settings.appendToResults() then drops the falsy entries, so nothing about environments reaches the dry-run output.
What is the expected behavior
The dry-run results include the planned environment changes, for example "Delete environment" for an environment that is no longer in the config.
Error output, if available
There's no runtime error. Output of the failing unit test below:
✕ BUG: sync() in nop mode returns the planned DELETE environment as a NopCommand
Expected value: "Delete environment"
Received array: []
Steps to reproduce
Repo my-org/my-repo has environments test and prod. Open a PR on the admin repo that changes settings.yml to:
environments:
- name: prod
The dry-run check shows nothing about deleting test.
Code references
remove(): lib/plugins/environments.js#L317-L321sync()return: #L377-L378- Results collected and falsy entries dropped: lib/settings.js#L2150-L2153, #L3173
Failing test
Fails on 3.0.0 and on main-enterprise.
it('BUG: sync() in nop mode returns the planned DELETE environment as a NopCommand', async () => {
const github = mockGithub({ prod: { api: apiEnv('prod') }, old: { api: apiEnv('old') } })
const plugin = new Environments(true, github, { owner: org, repo }, [{ name: 'prod' }], log, [])
const res = await plugin.sync()
const commands = [res].flat(3).filter(x => x instanceof NopCommand)
expect(commands.map(c => c.action.msg)).toContain('Delete environment')
})
Suggested fix
Return the nopifyRequest results from add/update/remove, and await Promise.all(changes) before returning resArray in nop mode.
This is separate from #1133: fixing the additive check there doesn't change what nop mode reports.
Context
Are you using the hosted instance of probot/settings or running your own?
Running our own. I reproduced this with unit tests against the code, using a mocked GitHub API, so it doesn't depend on how the app is deployed.
If running your own instance, are you using it with github.com or GitHub Enterprise?
Not relevant here: the reproduction uses a mocked API, and the code path is the same for both.
Version of probot/settings
safe-settings 3.0.0 (a9a1f366ad6a738b55682d346d94f8d6c4893b09), and main-enterprise at e19444e0d69de050ba55d0262b71fcd8a98edfef.
Version of GitHub Enterprise
N/A
Test helpers (mocks)
/* eslint-disable no-undef */
// Reproductions for reported Environments plugin bugs. Tests assert the
// CORRECT behaviour; the ones marked "BUG" fail against the current code.
const { when } = require('jest-when')
const Environments = require('../../../../lib/plugins/environments')
const Settings = require('../../../../lib/settings')
const NopCommand = require('../../../../lib/nopcommand')
const org = 'my-org'
const repo = 'my-repo'
const DELETE_ENV = 'DELETE /repos/:org/:repo/environments/:environment_name'
const PUT_ENV = 'PUT /repos/:org/:repo/environments/:environment_name'
const POST_RULE = 'POST /repos/:org/:repo/environments/:environment_name/deployment_protection_rules'
const DELETE_RULE = 'DELETE /repos/:org/:repo/environments/:environment_name/deployment_protection_rules/:rule_id'
const DELETE_VAR = 'DELETE /repos/:org/:repo/environments/:environment_name/variables/:variable_name'
// GitHub API shape of GET /repos/{owner}/{repo}/environments entries.
function apiEnv (name, { waitTimer, reviewers, preventSelfReview, branchPolicy = null } = {}) {
const protectionRules = []
if (waitTimer) protectionRules.push({ id: 1, type: 'wait_timer', wait_timer: waitTimer })
if (reviewers) {
protectionRules.push({
id: 2,
type: 'required_reviewers',
prevent_self_review: !!preventSelfReview,
reviewers: reviewers.map(r => ({ type: r.type, reviewer: { id: r.id } }))
})
}
return { name, protection_rules: protectionRules, deployment_branch_policy: branchPolicy }
}
// existing: { [envName]: { api, variables: [{name,value}], rules: [{id, app: {id}}] } }
function mockGithub (existing) {
const github = {
request: jest.fn(() => Promise.resolve({})),
paginate: jest.fn().mockResolvedValue([])
}
when(github.request)
.calledWith('GET /repos/:org/:repo/environments', { org, repo })
.mockResolvedValue({ data: { environments: Object.values(existing).map(e => e.api) } })
for (const [name, e] of Object.entries(existing)) {
when(github.request)
.calledWith('GET /repos/:org/:repo/environments/:environment_name/deployment_protection_rules', { org, repo, environment_name: name })
.mockResolvedValue({ data: { total_count: (e.rules || []).length, custom_deployment_protection_rules: e.rules || [] } })
when(github.paginate)
.calledWith('GET /repos/{owner}/{repo}/environments/{environment_name}/variables', expect.objectContaining({ environment_name: name }), expect.any(Function))
.mockResolvedValue(e.variables || [])
}
return github
}
function writeCalls (github) {
return github.request.mock.calls
.filter(([route]) => !route.startsWith('GET '))
.map(([route, opts]) => ({ route, opts }))
}
const log = { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() }
- 主要言語
- JavaScript
- スター
- 942
- フォーク
- 238
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github-community-projects/safe-settings のほかの issue
-
Teams: teams with organization-role access show up as deletions対応中かも @TovaBecker が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
github-community-projects/safe-settings#1144 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
github-community-projects/safe-settings#1143 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
github-community-projects/safe-settings#1134 ·
メンテナーはふだん 2 日以内に返信
-
environments: additive_plugins is ignored, undeclared environments are deleted対応中かも @yaunj が 12 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
github-community-projects/safe-settings#1133 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
github-community-projects/safe-settings#1130 ·
メンテナーはふだん 2 日以内に返信
github-community-projects/safe-settings の issue をすべて見る
似ている issue
-
priority: low server testing
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
blamechris/chroxy#9277 ·
メンテナーはふだん 1 日以内に返信
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
microsoft/playwright#44289 ·
メンテナーはふだん 1 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Ionaru/easy-markdown-editor#657 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
TMHSDigital/Free-Game-Dev-Assets#320 ·
メンテナーはふだん 1 日以内に返信
-
area:webapp bug finding
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信