Compare commits

..

6 Commits

Author SHA1 Message Date
Peter Evans
163be38112 Reset git client's extraheader list to remove local config 2020-03-07 08:50:57 +09:00
Peter Evans
01aa132594 Override auth extraheader with more specific url for git-lfs client 2020-03-07 08:50:49 +09:00
Peter Evans
f6dff3ab2e Revert unset and restore of auth extraheader 2020-03-07 08:50:43 +09:00
Peter Evans
64c34f6885 Update README 2020-03-03 09:49:52 +09:00
Peter Evans
ce00b952cf Merge pull request #128 from peter-evans/dev
Unset and restore authorization extraheader only
2020-02-22 17:02:15 +09:00
Peter Evans
0d42c285a3 Unset and restore authorization extraheader only 2020-02-22 16:56:42 +09:00
10 changed files with 10 additions and 5380 deletions

View File

@@ -181,6 +181,7 @@ jobs:
labels: report, automated pr
assignees: peter-evans
reviewers: peter-evans
team-reviewers: owners, maintainers
milestone: 1
project: Example Project
project-column: To do

View File

@@ -129,7 +129,10 @@ if protocol == "HTTPS":
# Mask the basic credential in logs and debug output
print(f"::add-mask::{basic_credential}")
repo.git.set_persistent_git_options(
c=f"http.https://github.com/.extraheader=AUTHORIZATION: basic {basic_credential}"
c=[
f"http.{repo_url}/.extraheader=",
f"http.{repo_url}/.extraheader=AUTHORIZATION: basic {basic_credential}",
]
)
# Determine if the checked out ref is a valid base for a pull request

127
dist/index.js vendored
View File

@@ -4215,13 +4215,6 @@ const isDocker = __webpack_require__(160);
const core = __webpack_require__(470);
const exec = __webpack_require__(986);
const setupPython = __webpack_require__(104);
const {
getRepoPath,
getAndUnsetConfigOption,
addConfigOption
} = __webpack_require__(718);
const EXTRAHEADER_OPTION = "http.https://github.com/.extraheader";
async function run() {
try {
@@ -4298,136 +4291,16 @@ async function run() {
if (inputs.base) process.env.CPR_BASE = inputs.base;
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Get the repository path
var repoPath = getRepoPath(inputs.path);
// Get the extraheader config option if it exists
var extraHeaderOptionValue = await getAndUnsetConfigOption(
repoPath,
EXTRAHEADER_OPTION
);
// Execute create pull request
await exec.exec(python, [`${cpr}/create_pull_request.py`]);
} catch (error) {
core.setFailed(error.message);
} finally {
// Restore the extraheader config option
if (extraHeaderOptionValue) {
if (
await addConfigOption(
repoPath,
EXTRAHEADER_OPTION,
extraHeaderOptionValue
)
)
core.debug(`Restored config option '${EXTRAHEADER_OPTION}'`);
}
}
}
run();
/***/ }),
/***/ 718:
/***/ (function(module, __unusedexports, __webpack_require__) {
const core = __webpack_require__(470);
const exec = __webpack_require__(986);
const path = __webpack_require__(622);
function getRepoPath(relativePath) {
let githubWorkspacePath = process.env["GITHUB_WORKSPACE"];
if (!githubWorkspacePath) {
throw new Error("GITHUB_WORKSPACE not defined");
}
githubWorkspacePath = path.resolve(githubWorkspacePath);
core.debug(`githubWorkspacePath: ${githubWorkspacePath}`);
repoPath = githubWorkspacePath;
if (relativePath) repoPath = path.resolve(repoPath, relativePath);
core.debug(`repoPath: ${repoPath}`);
return repoPath;
}
async function execGit(repoPath, args, ignoreReturnCode = false) {
const stdout = [];
const options = {
cwd: repoPath,
ignoreReturnCode: ignoreReturnCode,
listeners: {
stdout: data => {
stdout.push(data.toString());
}
}
};
var result = {};
result.exitCode = await exec.exec("git", args, options);
result.stdout = stdout.join("");
return result;
}
async function addConfigOption(repoPath, name, value) {
const result = await execGit(
repoPath,
["config", "--local", "--add", name, value],
true
);
return result.exitCode === 0;
}
async function unsetConfigOption(repoPath, name) {
const result = await execGit(
repoPath,
["config", "--local", "--unset", name],
true
);
return result.exitCode === 0;
}
async function configOptionExists(repoPath, name) {
const result = await execGit(
repoPath,
["config", "--local", "--name-only", "--get-regexp", name],
true
);
return result.exitCode === 0;
}
async function getConfigOption(repoPath, name) {
const result = await execGit(
repoPath,
["config", "--local", name],
true
);
return result.stdout.trim();
}
async function getAndUnsetConfigOption(repoPath, name) {
if (await configOptionExists(repoPath, name)) {
const extraHeaderOptionValue = await getConfigOption(repoPath, name);
if (await unsetConfigOption(repoPath, name)) {
core.debug(`Unset config option '${name}'`);
return extraHeaderOptionValue;
}
}
return null;
}
module.exports = {
getRepoPath,
execGit,
addConfigOption,
unsetConfigOption,
configOptionExists,
getConfigOption,
getAndUnsetConfigOption
};
/***/ }),
/***/ 722:

View File

@@ -1,3 +0,0 @@
process.env = Object.assign(process.env, {
GITHUB_WORKSPACE: __dirname
});

5053
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,6 @@
"scripts": {
"clean": "rm -rf dist",
"lint": "eslint src/index.js",
"test": "eslint src/index.js && jest",
"build": "ncc build src/index.js -o dist",
"vendor-deps": "pip download -r src/cpr/requirements.txt --no-binary=:all: -d dist/vendor",
"package": "npm run build && npm run vendor-deps"
@@ -30,7 +29,6 @@
},
"devDependencies": {
"@zeit/ncc": "0.21.1",
"eslint": "6.8.0",
"jest": "25.1.0"
"eslint": "6.8.0"
}
}

View File

@@ -129,7 +129,10 @@ if protocol == "HTTPS":
# Mask the basic credential in logs and debug output
print(f"::add-mask::{basic_credential}")
repo.git.set_persistent_git_options(
c=f"http.https://github.com/.extraheader=AUTHORIZATION: basic {basic_credential}"
c=[
f"http.{repo_url}/.extraheader=",
f"http.{repo_url}/.extraheader=AUTHORIZATION: basic {basic_credential}",
]
)
# Determine if the checked out ref is a valid base for a pull request

View File

@@ -1,93 +0,0 @@
const core = require("@actions/core");
const exec = require("@actions/exec");
const path = require("path");
function getRepoPath(relativePath) {
let githubWorkspacePath = process.env["GITHUB_WORKSPACE"];
if (!githubWorkspacePath) {
throw new Error("GITHUB_WORKSPACE not defined");
}
githubWorkspacePath = path.resolve(githubWorkspacePath);
core.debug(`githubWorkspacePath: ${githubWorkspacePath}`);
repoPath = githubWorkspacePath;
if (relativePath) repoPath = path.resolve(repoPath, relativePath);
core.debug(`repoPath: ${repoPath}`);
return repoPath;
}
async function execGit(repoPath, args, ignoreReturnCode = false) {
const stdout = [];
const options = {
cwd: repoPath,
ignoreReturnCode: ignoreReturnCode,
listeners: {
stdout: data => {
stdout.push(data.toString());
}
}
};
var result = {};
result.exitCode = await exec.exec("git", args, options);
result.stdout = stdout.join("");
return result;
}
async function addConfigOption(repoPath, name, value) {
const result = await execGit(
repoPath,
["config", "--local", "--add", name, value],
true
);
return result.exitCode === 0;
}
async function unsetConfigOption(repoPath, name) {
const result = await execGit(
repoPath,
["config", "--local", "--unset", name],
true
);
return result.exitCode === 0;
}
async function configOptionExists(repoPath, name) {
const result = await execGit(
repoPath,
["config", "--local", "--name-only", "--get-regexp", name],
true
);
return result.exitCode === 0;
}
async function getConfigOption(repoPath, name) {
const result = await execGit(
repoPath,
["config", "--local", name],
true
);
return result.stdout.trim();
}
async function getAndUnsetConfigOption(repoPath, name) {
if (await configOptionExists(repoPath, name)) {
const extraHeaderOptionValue = await getConfigOption(repoPath, name);
if (await unsetConfigOption(repoPath, name)) {
core.debug(`Unset config option '${name}'`);
return extraHeaderOptionValue;
}
}
return null;
}
module.exports = {
getRepoPath,
execGit,
addConfigOption,
unsetConfigOption,
configOptionExists,
getConfigOption,
getAndUnsetConfigOption
};

View File

@@ -1,72 +0,0 @@
const path = require("path");
const {
getRepoPath,
execGit,
addConfigOption,
unsetConfigOption,
configOptionExists,
getConfigOption,
getAndUnsetConfigOption
} = require("./git");
test("getRepoPath", async () => {
expect(getRepoPath()).toEqual(process.env["GITHUB_WORKSPACE"]);
expect(getRepoPath("foo")).toEqual(
path.resolve(process.env["GITHUB_WORKSPACE"], "foo")
);
});
test("execGit", async () => {
const repoPath = getRepoPath();
const result = await execGit(
repoPath,
["config", "--local", "--name-only", "--get-regexp", "remote.origin.url"],
true
);
expect(result.exitCode).toEqual(0);
expect(result.stdout.trim()).toEqual("remote.origin.url");
});
test("add and unset config option", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.add.and.unset.config.option", "true");
expect(add).toBeTruthy();
const unset = await unsetConfigOption(repoPath, "test.add.and.unset.config.option");
expect(unset).toBeTruthy();
});
test("configOptionExists returns true", async () => {
const repoPath = getRepoPath();
const result = await configOptionExists(repoPath, "remote.origin.url");
expect(result).toBeTruthy();
});
test("configOptionExists returns false", async () => {
const repoPath = getRepoPath();
const result = await configOptionExists(repoPath, "this.key.does.not.exist");
expect(result).toBeFalsy();
});
test("get config option", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.get.config.option", "foo");
expect(add).toBeTruthy();
const get = await getConfigOption(repoPath, "test.get.config.option");
expect(get).toEqual("foo");
const unset = await unsetConfigOption(repoPath, "test.get.config.option");
expect(unset).toBeTruthy();
});
test("get and unset config option is successful", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.get.and.unset.config.option", "foo");
expect(add).toBeTruthy();
const getAndUnset = await getAndUnsetConfigOption(repoPath, "test.get.and.unset.config.option");
expect(getAndUnset).toEqual("foo");
});
test("get and unset config option is unsuccessful", async () => {
const repoPath = getRepoPath();
const getAndUnset = await getAndUnsetConfigOption(repoPath, "this.key.does.not.exist");
expect(getAndUnset).toBeNull();
});

View File

@@ -3,13 +3,6 @@ const isDocker = require("is-docker");
const core = require("@actions/core");
const exec = require("@actions/exec");
const setupPython = require("./setup-python");
const {
getRepoPath,
getAndUnsetConfigOption,
addConfigOption
} = require("./git");
const EXTRAHEADER_OPTION = "http.https://github.com/.extraheader";
async function run() {
try {
@@ -86,30 +79,10 @@ async function run() {
if (inputs.base) process.env.CPR_BASE = inputs.base;
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Get the repository path
var repoPath = getRepoPath(inputs.path);
// Get the extraheader config option if it exists
var extraHeaderOptionValue = await getAndUnsetConfigOption(
repoPath,
EXTRAHEADER_OPTION
);
// Execute create pull request
await exec.exec(python, [`${cpr}/create_pull_request.py`]);
} catch (error) {
core.setFailed(error.message);
} finally {
// Restore the extraheader config option
if (extraHeaderOptionValue) {
if (
await addConfigOption(
repoPath,
EXTRAHEADER_OPTION,
extraHeaderOptionValue
)
)
core.debug(`Restored config option '${EXTRAHEADER_OPTION}'`);
}
}
}