danger-js icon indicating copy to clipboard operation
danger-js copied to clipboard

Feature: Expose --id to rules

Open glensc opened this issue 3 years ago • 6 comments

I want to get the value of danger ci --id to use in rules.

The intent is to run danger twice on CI pipeline, first time early to report coding errors, second time late to grab any artifacts from CI jobs and format them as comments.

The property itself is here:

  • https://github.com/danger/danger-js/blob/0b2c1d33d3336b80437d48af1c851e97751e3247/source/commands/ci/runner.ts#L66

glensc avatar May 10 '22 16:05 glensc

for now i'll use environment variable in my rules:

export const DANGER_ID = process.env.DANGER_ID || 'Danger';

but that's just duplicating the same thing, I need to set the env and need to pass --id arg when executing danger second time on the pipeline

glensc avatar May 10 '22 16:05 glensc

Ideas, guides? on how to implement this?

glensc avatar May 10 '22 17:05 glensc

We run two different Dangerfiles in our repo, so we don't need access to the ID within a single Dangerfile. Is that technique worthwhile for you @glensc?

danger ci --id "$1" --dangerfile "$DANGER_FILES_DIR/$1.ts" where $1 is the name of the file we're executing.

This then lets us easily trigger different danger files from different events or steps in a Github Actions Workflow, and not have them trip over each other.

fbartho avatar May 10 '22 21:05 fbartho

Feels like a field which could be available in the main danger export to me

orta avatar May 11 '22 06:05 orta

@orta, so something here:

  • https://github.com/danger/danger-js/blob/0b2c1d33d3336b80437d48af1c851e97751e3247/source/runner/jsonToDSL.ts#L54-L67

just add root level dangerId there? or as some structure? or under utils?

glensc avatar May 11 '22 08:05 glensc

I think dangerID in there would be 👍🏻 (utils is for functions IMO)

orta avatar May 11 '22 11:05 orta