Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
setup-java/node_modules/@actions/core/lib/command.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
66 lines (66 sloc)
2.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
const os = require("os"); | |
/** | |
* Commands | |
* | |
* Command Format: | |
* ##[name key=value;key=value]message | |
* | |
* Examples: | |
* ##[warning]This is the user warning message | |
* ##[set-secret name=mypassword]definatelyNotAPassword! | |
*/ | |
function issueCommand(command, properties, message) { | |
const cmd = new Command(command, properties, message); | |
process.stdout.write(cmd.toString() + os.EOL); | |
} | |
exports.issueCommand = issueCommand; | |
function issue(name, message) { | |
issueCommand(name, {}, message); | |
} | |
exports.issue = issue; | |
const CMD_PREFIX = '##['; | |
class Command { | |
constructor(command, properties, message) { | |
if (!command) { | |
command = 'missing.command'; | |
} | |
this.command = command; | |
this.properties = properties; | |
this.message = message; | |
} | |
toString() { | |
let cmdStr = CMD_PREFIX + this.command; | |
if (this.properties && Object.keys(this.properties).length > 0) { | |
cmdStr += ' '; | |
for (const key in this.properties) { | |
if (this.properties.hasOwnProperty(key)) { | |
const val = this.properties[key]; | |
if (val) { | |
// safely append the val - avoid blowing up when attempting to | |
// call .replace() if message is not a string for some reason | |
cmdStr += `${key}=${escape(`${val || ''}`)};`; | |
} | |
} | |
} | |
} | |
cmdStr += ']'; | |
// safely append the message - avoid blowing up when attempting to | |
// call .replace() if message is not a string for some reason | |
const message = `${this.message || ''}`; | |
cmdStr += escapeData(message); | |
return cmdStr; | |
} | |
} | |
function escapeData(s) { | |
return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A'); | |
} | |
function escape(s) { | |
return s | |
.replace(/\r/g, '%0D') | |
.replace(/\n/g, '%0A') | |
.replace(/]/g, '%5D') | |
.replace(/;/g, '%3B'); | |
} | |
//# sourceMappingURL=command.js.map |