Skip to content

Commit 7447870

Browse files
authored
Merge pull request #3 from tspascoal/add-expiration-to-output
Add tokenExpiration as an output variable
2 parents 87e7bfb + f9a1546 commit 7447870

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ steps:
7878

7979
| Variable | Description |
8080
|----------|-------------|
81-
| $(installationToken) | The generated GitHub App installation token |
82-
| $(installationId) | The ID of the GitHub App installation |
81+
| installationToken | The generated GitHub App installation token |
82+
| installationId | The ID of the GitHub App installation |
83+
| tokenExpiration | The expiration date and time of the generated token (ISO 8601 format) |
8384

8485
### Service Connection Setup (optional)
8586

create-github-app-token/src/core/github-service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ export class GitHubService {
135135
* It logs details about the token creation process, including repository selection and permissions.
136136
* The token is scoped based on the provided repositories or the entire installation if no repositories are specified.
137137
*/
138-
async getInstallationToken(jwtToken: string, installationId: number, repositories: string[] = [], permissions?: { [key: string]: string }): Promise<string> {
138+
async getInstallationToken(jwtToken: string, installationId: number, repositories: string[] = [], permissions?: { [key: string]: string }): Promise<{ token: string; expiresAt: string }> {
139139
let groupName = '';
140140
let token = '';
141+
let expiresAt = '';
141142
if (repositories.length > 0) {
142143
groupName = `##[group]Create installation token for repositories: ${repositories} with ${installationId}`;
143144
} else {
@@ -167,10 +168,11 @@ export class GitHubService {
167168
);
168169

169170
token = response.data.token;
171+
expiresAt = response.data.expires_at;
170172

171173
this.dumpHeaders(response.headers);
172174

173-
tl.debug(`Expires: ${response.data.expires_at}`);
175+
tl.debug(`Expires: ${expiresAt}`);
174176
console.log(`Repository selection: ${response.data.repository_selection}`);
175177
const permissionsCsv = this.formatPermissions(response.data.permissions);
176178
console.log(`Permissions: ${permissionsCsv}`);
@@ -179,7 +181,7 @@ export class GitHubService {
179181
console.log('##[endgroup]')
180182
}
181183

182-
return token;
184+
return { token, expiresAt };
183185
}
184186

185187
async revokeInstallationToken(token: string): Promise<boolean> {

create-github-app-token/src/tasks/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ async function run() {
169169
const installationId = await githubService.getInstallationId(jwtToken, owner, isOrg, repositories);
170170
console.log(`Found installation ID: ${installationId}`);
171171

172-
const token = await githubService.getInstallationToken(jwtToken, installationId, repositories, permissions);
172+
const { token, expiresAt } = await githubService.getInstallationToken(jwtToken, installationId, repositories, permissions);
173173
console.log('Installation token generated successfully');
174174

175175
// Set the output variables
176176
tl.setVariable(constants.INSTALLATIONID_OUTPUT_VARNAME, installationId.toString(), false);
177177
tl.setVariable(constants.INSTALLATION_TOKEN_OUTPUT_VARNAME, token, true); // secret
178+
tl.setVariable(constants.TOKEN_EXPIRATION_OUTPUT_VARNAME, expiresAt, false);
178179

179180
// Save state for post job
180181
tl.setTaskVariable(constants.INSTALLATION_TOKEN_OUTPUT_VARNAME, token, true); // secret

create-github-app-token/src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const JWT_EXPIRATION = 10 * 60; // 10 minutes in seconds (max is 10 minut
33

44
export const INSTALLATIONID_OUTPUT_VARNAME = 'installationId';
55
export const INSTALLATION_TOKEN_OUTPUT_VARNAME = 'installationToken';
6+
export const TOKEN_EXPIRATION_OUTPUT_VARNAME = 'tokenExpiration';
67
export const SKIP_TOKEN_TASK_VARNAME = 'skipTokenRevoke';
78
export const BASE_URL_TASK_VARNAME = 'baseUrl';
89

create-github-app-token/task.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"version": {
1111
"Major": 1,
1212
"Minor": 0,
13-
"Patch": 2
13+
"Patch": 3
1414
},
1515
"instanceNameFormat": "Create GitHub App Installation Token",
1616
"inputs": [
@@ -91,6 +91,10 @@
9191
{
9292
"name": "installationId",
9393
"description": "The ID of the GitHub App installation"
94+
},
95+
{
96+
"name": "tokenExpiration",
97+
"description": "The expiration date and time of the generated token (ISO 8601 format)"
9498
}
9599
],
96100
"execution": {

vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "create-github-app-token",
44
"name": "GitHub App Token Generator",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"publisher": "INSERT YOUR PUBLISHER HERE",
77
"public": false,
88
"targets": [

0 commit comments

Comments
 (0)