Fix pull_request_target event

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-05-25 18:45:23 +02:00
parent 013e892d4a
commit 85f4f732f2
3 changed files with 80 additions and 40 deletions

View File

@ -27,6 +27,12 @@ export class Meta {
private readonly date: Date;
constructor(inputs: Inputs, context: Context, repo: ReposGetResponseData) {
// Needs to override Git reference with pr ref instead of upstream branch ref
// for pull_request_target event
if (/pull_request_target/.test(context.eventName)) {
context.ref = `refs/pull/${context.payload.number}/merge`;
}
this.inputs = inputs;
this.context = context;
this.repo = repo;
@ -191,15 +197,11 @@ export class Meta {
}
private procRefPr(version: Version, tag: tcl.Tag): Version {
let ref = this.context.ref;
if (/pull_request_target/.test(this.context.eventName)) {
ref = `refs/pull/${this.context.payload.number}/merge`;
}
if (!/^refs\/pull\//.test(ref)) {
if (!/^refs\/pull\//.test(this.context.ref)) {
return version;
}
const vraw = this.setValue(ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
}