var E=Object.defineProperty;var c=(e,t)=>E(e,"name",{value:t,configurable:!0});import{createRequire as p}from"node:module";import{l as f,B as A}from"./readFileSync-DseCu8sg-DEq4Fn3a.js";const g=p(import.meta.url),l=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=c(e=>{if(typeof l<"u"&&l.versions&&l.versions.node){const[t,r]=l.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return l.getBuiltinModule(e)}return g(e)},"__cjs_getBuiltinModule"),{spawnSync:b}=h("node:child_process");var v=Object.defineProperty,i=c((e,t)=>v(e,"name",{value:t,configurable:!0}),"o");const I="0000000000000000000000000000000000000000",R=i(e=>{if(f(e))try{const t=A(e);return JSON.parse(t)}catch{return}},"defaultReadEventPayload"),C=i((e,t)=>{const r=b("git",e,{cwd:t,encoding:"utf8"});if(!(r.error||typeof r.status!="number"||r.status!==0))return typeof r.stdout=="string"?r.stdout.trim():void 0},"defaultRunGit"),d=i(e=>typeof e=="string"&&e.length>0&&e!==I,"isNonEmptySha");i((e,...t)=>{let r=e;for(const o of t){if(r===null||typeof r!="object")return;r=r[o]}return r},"getNested");const B=i((e,t,r)=>{const o=[],s=e.GITHUB_BASE_REF,n=e.GITHUB_SHA??"HEAD";if(s&&s.length>0)return o.push(`pull_request: $GITHUB_BASE_REF=${s}`),{base:`origin/${s}`,head:n,notes:o,provider:"github"};const u=e.GITHUB_EVENT_PATH,a=u?r(u):void 0;if(a){const _=typeof a.before=="string"?a.before:void 0;if(d(_))return o.push(`push: event.before=${_}`),{base:_,head:n,notes:o,provider:"github"}}return o.push(`fallback: origin/${t}`),{base:`origin/${t}`,head:n,notes:o,provider:"github"}},"resolveGithub"),T=i((e,t)=>{const r=[],o=e.CI_COMMIT_SHA??"HEAD";if(e.CI_PIPELINE_SOURCE==="merge_request_event"){const u=e.CI_MERGE_REQUEST_DIFF_BASE_SHA;if(d(u))return r.push(`merge_request: $CI_MERGE_REQUEST_DIFF_BASE_SHA=${u}`),{base:u,head:o,notes:r,provider:"gitlab"};const a=e.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;if(a&&a.length>0)return r.push(`merge_request: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME=${a}`),{base:`origin/${a}`,head:o,notes:r,provider:"gitlab"}}const s=e.CI_COMMIT_BEFORE_SHA;if(d(s))return r.push(`push: $CI_COMMIT_BEFORE_SHA=${s}`),{base:s,head:o,notes:r,provider:"gitlab"};const n=e.CI_DEFAULT_BRANCH??t;return r.push(`fallback: origin/${n}`),{base:`origin/${n}`,head:o,notes:r,provider:"gitlab"}},"resolveGitlab"),$=i((e,t)=>{const r=[],o=e.BUILDKITE_COMMIT??"HEAD",s=e.BUILDKITE_PULL_REQUEST_BASE_BRANCH;return s&&s.length>0?(r.push(`pull_request: $BUILDKITE_PULL_REQUEST_BASE_BRANCH=${s}`),{base:`origin/${s}`,head:o,notes:r,provider:"buildkite"}):(r.push(`fallback: origin/${t} (buildkite has no canonical previous-build SHA env)`),{base:`origin/${t}`,head:o,notes:r,provider:"buildkite"})},"resolveBuildkite"),H=i((e,t)=>{const r=[],o=e.CIRCLE_SHA1??"HEAD",s=e.CIRCLE_PR_BASE_BRANCH;return s&&s.length>0?(r.push(`pull_request: $CIRCLE_PR_BASE_BRANCH=${s}`),{base:`origin/${s}`,head:o,notes:r,provider:"circleci"}):(r.push(`fallback: origin/${t} (circleci has no canonical previous-build SHA env)`),{base:`origin/${t}`,head:o,notes:r,provider:"circleci"})},"resolveCircleCI"),S=i((e,t,r)=>{const o=[],s=t(["merge-base","HEAD",`origin/${e}`],r);return s&&s.length>0?(o.push(`local: git merge-base HEAD origin/${e}=${s}`),{base:s,head:"HEAD",notes:o,provider:"local"}):(o.push(`local fallback: origin/${e} (no merge-base available)`),{base:`origin/${e}`,head:"HEAD",notes:o,provider:"local"})},"resolveLocal"),L=i(e=>{const t=e?.env??process.env,r=e?.defaultBase??"main",o=e?.readEventPayload??R,s=e?.runGit??C,n=e?.workspaceRoot??process.cwd();return t.GITHUB_ACTIONS==="true"?B(t,r,o):t.GITLAB_CI==="true"?T(t,r):t.BUILDKITE==="true"?$(t,r):t.CIRCLECI==="true"?H(t,r):S(r,s,n)},"resolveAffectedShas");export{L as r};
