Skip to content

Commit

Permalink
fix: manage absolute path (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
thollander authored Jan 14, 2023
1 parent 18002f5 commit dffae49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: (BEFORE) Setup test cases
run: echo '**Content of file referenced with absolute path**' > /tmp/foobar.txt

- name: Comment PR with message
uses: ./
with:
Expand All @@ -28,9 +31,20 @@ jobs:
reactions: eyes, rocket
mode: recreate

- name: Comment PR with file (absolute path)
uses: ./
with:
filePath: /tmp/foobar.txt
comment_tag: nrt_file_absolute
reactions: eyes, rocket
mode: recreate

- name: Do not comment PR if not exists
uses: ./
with:
message: Should not be printed
comment_tag: nrt_create_if_not_exists
create_if_not_exists: false
create_if_not_exists: false

- name: (AFTER) Setup test cases
run: rm /tmp/foobar.txt
10 changes: 1 addition & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9539,7 +9539,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const github = __importStar(__nccwpck_require__(5438));
const core = __importStar(__nccwpck_require__(2186));
Expand All @@ -9560,15 +9559,8 @@ async function run() {
return;
}
let content = message;
let _filePath;
if (!message && filePath) {
const { GITHUB_WORKSPACE } = process.env;
if (!GITHUB_WORKSPACE) {
core.setFailed('"GITHUB_WORKSPACE" env variable is not defined.');
return;
}
_filePath = path_1.default.join(GITHUB_WORKSPACE, filePath);
content = fs_1.default.readFileSync(_filePath, 'utf8');
content = fs_1.default.readFileSync(filePath, 'utf8');
}
const context = github.context;
const issue_number = parseInt(pr_number) || context.payload.pull_request?.number || context.payload.issue?.number;
Expand Down
11 changes: 1 addition & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ async function run() {
}

let content: string = message;
let _filePath: string;
if (!message && filePath) {
const { GITHUB_WORKSPACE } = process.env;

if (!GITHUB_WORKSPACE) {
core.setFailed('"GITHUB_WORKSPACE" env variable is not defined.');
return;
}

_filePath = path.join(GITHUB_WORKSPACE, filePath);
content = fs.readFileSync(_filePath, 'utf8');
content = fs.readFileSync(filePath, 'utf8');
}

const context = github.context;
Expand Down

0 comments on commit dffae49

Please sign in to comment.