Skip to content

Commit

Permalink
chore: add token file read for register source
Browse files Browse the repository at this point in the history
  • Loading branch information
florianow committed Nov 7, 2024
1 parent a226925 commit e3c6a35
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
32 changes: 19 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,27 @@ async function run() {
// Read token from the file
const tokenData = JSON.parse(fs.readFileSync(tokenFilePath, 'utf8'));
const fileToken = tokenData.token;
// Prepare the request payload and headers
const requestPayload = {
source: {
id: 'github',
externalRunId: github.context.runId,
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
},
steps: steps
};
const requestHeaders = {
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Accept': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Authorization': `Bearer ${fileToken}`
};
// Log the request payload and headers
core.debug(`Request Payload: ${JSON.stringify(requestPayload)}`);
core.debug(`Request Headers: ${JSON.stringify(requestHeaders)}`);
// Register the source
try {
const response = await axios_1.default.post(`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source`, {
source: {
id: 'github',
externalRunId: github.context.runId,
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
},
steps: steps
}, {
headers: {
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Accept': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Authorization': `Bearer ${fileToken}`
}
const response = await axios_1.default.post(`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source`, requestPayload, {
headers: requestHeaders
});
core.setOutput('response', response.data);
core.setOutput('token_file', tokenFilePath);
Expand Down
34 changes: 21 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,32 @@ async function run() {
const tokenData = JSON.parse(fs.readFileSync(tokenFilePath, 'utf8'));
const fileToken = tokenData.token;

// Prepare the request payload and headers
const requestPayload = {
source: {
id: 'github',
externalRunId: github.context.runId,
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
},
steps: steps
};
const requestHeaders = {
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Accept': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Authorization': `Bearer ${fileToken}`
};

// Log the request payload and headers
core.debug(`Request Payload: ${JSON.stringify(requestPayload)}`);
core.debug(`Request Headers: ${JSON.stringify(requestHeaders)}`);

// Register the source
try {
const response = await axios.post(
`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source`,
requestPayload,
{
source: {
id: 'github',
externalRunId: github.context.runId,
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
},
steps: steps
},
{
headers: {
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Accept': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
'Authorization': `Bearer ${fileToken}`
}
headers: requestHeaders
}
);

Expand Down

0 comments on commit e3c6a35

Please sign in to comment.