Add PR/MR detection to CI actions with comprehensive test coverage#909
Conversation
Co-authored-by: rsenden <8635138+rsenden@users.noreply.github.com>
|
@copilot what if we run detect-env.yaml in a not currently recognized CI system? Would that cause any issues? I guess for not recognized CI systems, we should default to global.ci.prActive=false, and global.ci.prTerminology to 'Pull Request'? |
Co-authored-by: rsenden <8635138+rsenden@users.noreply.github.com>
Good catch! For unrecognized CI systems (Jenkins, local Git, or no CI detection), the PR properties would have been null. I've added default values in commit 4f2565c:
This ensures the skip reason logic works correctly for all scenarios. |
|
@copilot now that we have cinsyatem detection and properties accessible through SpEL function, any way to simplify detect-env.yaml? For example:
|
Co-authored-by: rsenden <8635138+rsenden@users.noreply.github.com>
Done in commit f18202b: Java models:
detect-env.yaml simplification:
Result: 15 fewer lines, clearer structure, and PR terminology now comes from Java models instead of being hardcoded in YAML. |
|
@copilot Can we simplify further by adding CI name/id to the Java-based CI detection logic? |
Co-authored-by: rsenden <8635138+rsenden@users.noreply.github.com>
Done in commit 886c46d: Java models:
detect-env.yaml simplification:
Result: 18 fewer lines in detect-env.yaml. All CI-specific constants are now defined in Java models, making the YAML configuration purely data-driven. |
Co-authored-by: rsenden <8635138+rsenden@users.noreply.github.com>
|
|
||
| # For recognized CI systems (github, gitlab, ado, bitbucket), extract properties from detected environment | ||
| # Using conditional navigation operator ?. to safely access properties even if ci.env is null | ||
| - if: ${ci.type=='github'||ci.type=='gitlab'||ci.type=='ado'||ci.type=='bitbucket'} |
There was a problem hiding this comment.
@copilot I don't like this check for known CI systems, as we'd need to update this if we add support for new CI system in Java code. Can we reverse the check to check for 'not an unknown CI system'? What's returned by #_ci.detect() code in case of unknown CI system? Do we need any safe navigation in lines 49 & 50?
There was a problem hiding this comment.
Fixed in commit 27cd8c0:
Changed the check from ${ci.type=='github'||ci.type=='gitlab'||ci.type=='ado'||ci.type=='bitbucket'} to ${ci.type!='unknown'}.
#_ci.detect() returns ActionUnknownCiSpelFunctions for unknown CI systems, which has:
type = "unknown"envreturns an empty ObjectNode (never null)
Lines 49 & 50 don't need safe navigation because ci.detected is always non-null, and both type and env properties are always available. The ?. operators in lines 56-65 are still needed for navigating properties within ci.env since it may be empty for unknown CI systems.
All 11 functional tests still pass.
|
@copilot Please check review comment and fix |
Co-authored-by: rsenden <8635138+rsenden@users.noreply.github.com>
I've already addressed the review comment in commit 27cd8c0, changing the check from hardcoded CI system names to Could you please clarify what still needs to be fixed? The current implementation:
Is there a specific issue you'd like me to address? |
Test Results:
detect-env-githubto verifyprActive: falseandprNotActiveSkipReason: Not a Pull Requestdetect-env-gitlabto verifyprActive: falseandprNotActiveSkipReason: Not a Merge Requestdetect-env-github-prto verifyprActive: true,prId: 123,prTarget: main,prTerminology: Pull Requestdetect-env-gitlab-mrto verifyprActive: true,prId: 42,prTarget: main,prTerminology: Merge Requestdetect-env-ado-prto verify ADO PR detection with all propertiesdetect-env-bitbucket-prto verify Bitbucket PR detection with all propertiesAll tests pass successfully!
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.