Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add GitHub App's slug (app-slug) output
  • Loading branch information
maboloshi committed Feb 20, 2024
commit a171f04890d8e3b8a42804df3d6751127e3a7e31
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ on: [push]

GitHub App installation access token.

### `app-slug`

GitHub App's slug.

## How it works

The action creates an installation access token using [the `POST /app/installations/{installation_id}/access_tokens` endpoint](https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app). By default,
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ inputs:
outputs:
token:
description: "GitHub installation access token"
app-slug:
description: "GitHub App's slug"
runs:
using: "node20"
main: "dist/main.cjs"
Expand Down
168 changes: 89 additions & 79 deletions dist/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13800,15 +13800,16 @@ var require_util2 = __commonJS({
return result;
}
var esIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
function makeIterator(iterator, name, kind) {
function makeIterator(iterator, name, kind, keyIndex = 0, valueIndex = 1) {
const object = {
index: 0,
kind,
target: iterator
};
const i = {
next() {
if (Object.getPrototypeOf(this) !== i) {
const iteratorObject = Object.create(esIteratorPrototype);
Object.defineProperty(iteratorObject, "next", {
value: function next() {
if (Object.getPrototypeOf(this) !== iteratorObject) {
throw new TypeError(
`'next' called on an object that does not implement interface ${name} Iterator.`
);
Expand All @@ -13819,34 +13820,36 @@ var require_util2 = __commonJS({
if (index >= len) {
return { value: void 0, done: true };
}
const pair = values[index];
const { [keyIndex]: key, [valueIndex]: value } = values[index];
object.index = index + 1;
return iteratorResult(pair, kind2);
let result;
switch (kind2) {
case "key":
result = key;
break;
case "value":
result = value;
break;
case "key+value":
result = [key, value];
break;
}
return {
value: result,
done: false
};
},
// The class string of an iterator prototype object for a given interface is the
// result of concatenating the identifier of the interface and the string " Iterator".
[Symbol.toStringTag]: `${name} Iterator`
};
Object.setPrototypeOf(i, esIteratorPrototype);
return Object.setPrototypeOf({}, i);
}
function iteratorResult(pair, kind) {
let result;
switch (kind) {
case "key": {
result = pair[0];
break;
}
case "value": {
result = pair[1];
break;
}
case "key+value": {
result = pair;
break;
}
}
return { value: result, done: false };
writable: true,
enumerable: true,
configurable: true
});
Object.defineProperty(iteratorObject, Symbol.toStringTag, {
value: `${name} Iterator`,
writable: false,
enumerable: false,
configurable: true
});
return Object.create(iteratorObject);
}
async function fullyReadBody(body, processBody, processBodyError) {
const successSteps = processBody;
Expand Down Expand Up @@ -14716,9 +14719,10 @@ var require_formdata = __commonJS({
"use strict";
var { isBlobLike, toUSVString, makeIterator } = require_util2();
var { kState } = require_symbols2();
var { kEnumerableProperty } = require_util();
var { File: UndiciFile, FileLike, isFileLike } = require_file();
var { webidl } = require_webidl();
var { Blob: Blob2, File: NativeFile } = require("node:buffer");
var { File: NativeFile } = require("node:buffer");
var File = NativeFile ?? UndiciFile;
var FormData = class _FormData {
constructor(form) {
Expand Down Expand Up @@ -14799,24 +14803,30 @@ var require_formdata = __commonJS({
entries() {
webidl.brandCheck(this, _FormData);
return makeIterator(
() => this[kState].map((pair) => [pair.name, pair.value]),
() => this[kState],
"FormData",
"key+value"
"key+value",
"name",
"value"
);
}
keys() {
webidl.brandCheck(this, _FormData);
return makeIterator(
() => this[kState].map((pair) => [pair.name, pair.value]),
() => this[kState],
"FormData",
"key"
"key",
"name",
"value"
);
}
values() {
webidl.brandCheck(this, _FormData);
return makeIterator(
() => this[kState].map((pair) => [pair.name, pair.value]),
() => this[kState],
"FormData",
"value",
"name",
"value"
);
}
Expand All @@ -14833,12 +14843,23 @@ var require_formdata = __commonJS({
);
}
for (const [key, value] of this) {
callbackFn.apply(thisArg, [value, key, this]);
callbackFn.call(thisArg, value, key, this);
}
}
};
FormData.prototype[Symbol.iterator] = FormData.prototype.entries;
Object.defineProperties(FormData.prototype, {
append: kEnumerableProperty,
delete: kEnumerableProperty,
get: kEnumerableProperty,
getAll: kEnumerableProperty,
has: kEnumerableProperty,
set: kEnumerableProperty,
entries: kEnumerableProperty,
keys: kEnumerableProperty,
values: kEnumerableProperty,
forEach: kEnumerableProperty,
[Symbol.iterator]: { enumerable: false },
[Symbol.toStringTag]: {
value: "FormData",
configurable: true
Expand All @@ -14850,7 +14871,7 @@ var require_formdata = __commonJS({
value = Buffer.from(value).toString("utf8");
} else {
if (!isFileLike(value)) {
value = value instanceof Blob2 ? new File([value], "blob", { type: value.type }) : new FileLike(value, "blob", { type: value.type });
value = value instanceof Blob ? new File([value], "blob", { type: value.type }) : new FileLike(value, "blob", { type: value.type });
}
if (filename !== void 0) {
const options = {
Expand Down Expand Up @@ -21434,50 +21455,32 @@ var require_headers = __commonJS({
}
keys() {
webidl.brandCheck(this, _Headers);
if (this[kGuard] === "immutable") {
const value = this[kHeadersSortedMap];
return makeIterator(
() => value,
"Headers",
"key"
);
}
return makeIterator(
() => [...this[kHeadersSortedMap].values()],
() => this[kHeadersSortedMap],
"Headers",
"key"
"key",
0,
1
);
}
values() {
webidl.brandCheck(this, _Headers);
if (this[kGuard] === "immutable") {
const value = this[kHeadersSortedMap];
return makeIterator(
() => value,
"Headers",
"value"
);
}
return makeIterator(
() => [...this[kHeadersSortedMap].values()],
() => this[kHeadersSortedMap],
"Headers",
"value"
"value",
0,
1
);
}
entries() {
webidl.brandCheck(this, _Headers);
if (this[kGuard] === "immutable") {
const value = this[kHeadersSortedMap];
return makeIterator(
() => value,
"Headers",
"key+value"
);
}
return makeIterator(
() => [...this[kHeadersSortedMap].values()],
() => this[kHeadersSortedMap],
"Headers",
"key+value"
"key+value",
0,
1
);
}
/**
Expand All @@ -21493,7 +21496,7 @@ var require_headers = __commonJS({
);
}
for (const [key, value] of this) {
callbackFn.apply(thisArg, [value, key, this]);
callbackFn.call(thisArg, value, key, this);
}
}
[Symbol.for("nodejs.util.inspect.custom")]() {
Expand Down Expand Up @@ -23146,9 +23149,9 @@ var require_fetch = __commonJS({
internalResponse.body.stream.pipeThrough(transformStream);
const byteStream = new ReadableStream({
readableStream: transformStream.readable,
async start(controller) {
async pull(controller) {
const reader = this.readableStream.getReader();
while (true) {
while (controller.desiredSize >= 0) {
const { done, value } = await reader.read();
if (done) {
queueMicrotask(() => readableStreamClose(controller));
Expand All @@ -23157,6 +23160,7 @@ var require_fetch = __commonJS({
controller.enqueue(value);
}
},
queuingStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 16384 }),
type: "bytes"
});
internalResponse.body.stream = byteStream;
Expand Down Expand Up @@ -23248,6 +23252,7 @@ var require_fetch = __commonJS({
}
if (!sameOrigin(requestCurrentURL(request2), locationURL)) {
request2.headersList.delete("authorization", true);
request2.headersList.delete("proxy-authorization", true);
request2.headersList.delete("cookie", true);
request2.headersList.delete("host", true);
}
Expand Down Expand Up @@ -23473,6 +23478,7 @@ var require_fetch = __commonJS({
};
const stream = new ReadableStream(
{
highWaterMark: 16384,
async start(controller) {
fetchParams.controller.controller = controller;
},
Expand All @@ -23482,7 +23488,8 @@ var require_fetch = __commonJS({
async cancel(reason) {
await cancelAlgorithm(reason);
},
type: "bytes"
type: "bytes",
queuingStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 16384 })
}
);
response.body = { stream };
Expand Down Expand Up @@ -27693,28 +27700,29 @@ async function main(appId2, privateKey2, owner2, repositories2, core3, createApp
privateKey: privateKey2,
request: request2
});
let authentication;
let authentication, appSlug;
if (parsedRepositoryNames) {
authentication = await pRetry(() => getTokenFromRepository(request2, auth, parsedOwner, parsedRepositoryNames), {
({ authentication, appSlug } = await pRetry(() => getTokenFromRepository(request2, auth, parsedOwner, parsedRepositoryNames), {
onFailedAttempt: (error) => {
core3.info(
`Failed to create token for "${parsedRepositoryNames}" (attempt ${error.attemptNumber}): ${error.message}`
);
},
retries: 3
});
}));
} else {
authentication = await pRetry(() => getTokenFromOwner(request2, auth, parsedOwner), {
({ authentication, appSlug } = await pRetry(() => getTokenFromOwner(request2, auth, parsedOwner), {
onFailedAttempt: (error) => {
core3.info(
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`
);
},
retries: 3
});
}));
}
core3.setSecret(authentication.token);
core3.setOutput("token", authentication.token);
core3.setOutput("app-slug", appSlug);
if (!skipTokenRevoke2) {
core3.saveState("token", authentication.token);
core3.setOutput("expiresAt", authentication.expiresAt);
Expand All @@ -27740,7 +27748,8 @@ async function getTokenFromOwner(request2, auth, parsedOwner) {
type: "installation",
installationId: response.data.id
});
return authentication;
const appSlug = response.data["app_slug"];
return { authentication, appSlug };
}
async function getTokenFromRepository(request2, auth, parsedOwner, parsedRepositoryNames) {
const response = await request2("GET /repos/{owner}/{repo}/installation", {
Expand All @@ -27755,7 +27764,8 @@ async function getTokenFromRepository(request2, auth, parsedOwner, parsedReposit
installationId: response.data.id,
repositoryNames: parsedRepositoryNames.split(",")
});
return authentication;
const appSlug = response.data["app_slug"];
return { authentication, appSlug };
}

// lib/request.js
Expand Down
Loading