Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file support #119

Closed
wants to merge 3 commits into from
Closed

Conversation

EhsanHerai
Copy link

No description provided.

@thollander thollander self-requested a review September 6, 2022 07:52
Copy link
Owner

@thollander thollander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @EhsanHerai !
A bunch of comments of linting, docs and strategy around message > filePath

const github_token: string = core.getInput('GITHUB_TOKEN');
const pr_number: string = core.getInput('pr_number');
const comment_includes: string = core.getInput('comment_includes');
const reactions: string = core.getInput('reactions');

if(!filePath && !message) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!filePath && !message) {
if (!filePath && !message) {

Comment on lines +24 to +25
if(filePath) {
if(!process.env.GITHUB_WORKSPACE) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(filePath) {
if(!process.env.GITHUB_WORKSPACE) {
if (filePath) {
if (!process.env.GITHUB_WORKSPACE) {

const github_token: string = core.getInput('GITHUB_TOKEN');
const pr_number: string = core.getInput('pr_number');
const comment_includes: string = core.getInput('comment_includes');
const reactions: string = core.getInput('reactions');

if(!filePath && !message) {
throw new Error('either filePath or message input should be provided!');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('either filePath or message input should be provided!');
throw new Error('Either "filePath" or "message" input should be provided');


if(filePath) {
if(!process.env.GITHUB_WORKSPACE) {
throw new Error('GITHUB_WORKSPACE is not set! please make sure to use action/checkout action!');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('GITHUB_WORKSPACE is not set! please make sure to use action/checkout action!');
throw new Error('GITHUB_WORKSPACE is not set, please make sure to use actions/checkout action');

Comment on lines +28 to +29
const _path = path.join(process.env.GITHUB_WORKSPACE, filePath);
message = fs.readFileSync(_path, 'utf8');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const _path = path.join(process.env.GITHUB_WORKSPACE, filePath);
message = fs.readFileSync(_path, 'utf8');
const absolutefilePath = path.join(process.env.GITHUB_WORKSPACE, filePath);
message = fs.readFileSync(absolutefilePath, 'utf8');

required: true
required: false
filePath:
description: 'File that should be commented'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: 'File that should be commented'
description: 'File content that should be commented'

@@ -8,12 +10,25 @@ type Reaction = typeof REACTIONS[number];

async function run() {
try {
const message: string = core.getInput('message');
let message: string = core.getInput('message');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let message: string = core.getInput('message');
const message: string = core.getInput('message');

I'd prefer here to let the input variable let as it is.
Prefer creating a new variable that would be something like : body (defaults to = message) and override this one in case of the presence of fielPath

@@ -28,6 +28,25 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

### specify a file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### specify a file
### Specify a file

Here IMHO, we should also specify that in case this varibale is filled up, we override the message.

For instance :

      - name: Comment PR
        uses: thollander/actions-comment-pull-request@v1
        with:
          message: Hello !
          filePath: /path/to/file.txt
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Would go for the file and not the message.
Should it really be the default behaviour btw ? I think message should have more power than filePath in case it's present. Then I would go for an if (filePath && !message)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants