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

Prompts for inputs even when Arguments are passed #111

Closed
datsabk opened this issue Feb 28, 2024 · 25 comments · Fixed by #112
Closed

Prompts for inputs even when Arguments are passed #111

datsabk opened this issue Feb 28, 2024 · 25 comments · Fixed by #112
Labels

Comments

@datsabk
Copy link

datsabk commented Feb 28, 2024

Hello @joeyguerra ,
After your recent changes, the conditional prompts got converted to permanent prompts.

if (!this.options.owner) {
        prompts.push({
          name: 'botOwner',
          message: 'Owner',
          default: botOwner
        })
      }

This is how the prompts are expected to be. Instead, it now pushes all prompts even if options are passed. Could you please look into fixing the same.

@joeyguerra
Copy link
Member

@datsabk can you write a failing test for the scenario you're running into? Please note that the default username and email comes from the machine's git configured username and email.

@datsabk
Copy link
Author

datsabk commented Feb 28, 2024

Hello @joeyguerra ,
I basically try passing the options via arguments. Ideally it should not prompt me when those options are passed as flag.

my command looks like yo hubot --owner something --name gitbot....

What's happening currently is that all prompts seem to be pushed regardless of whether a default value is passed. I couldnt find the source of this.prompt() function that pushes the prompt. Does it filter in any way?

@joeyguerra
Copy link
Member

joeyguerra commented Feb 28, 2024

Update:
My apologies. I didn't finish reading your previous questions.

I think you have to call it like yo hubot --owner="something" --name="gitbot" .....

I see. I'm no longer making feature requests to this package because the current recommended way to generate a Hubot instance is as documented in the Hubot repo readme. Would you mind trying that instead? But I haven't added the ability to set the owner properties via cli arguments. You would just update the package.json directly with those values.

npx hubot --create myhubot --adapter @hubot-friends/hubot-slack

Where myhubot is the folder you want to create the bot in.

@hontarenko
Copy link

@joeyguerra I have the same issue with prompts for inputs even when arguments are passed. As a result, my image build broke :(

@joeyguerra
Copy link
Member

@hontarenko are you able to update your image with the new recommended way?

@hontarenko
Copy link

@joeyguerra Сan you provide an example of Dockerfile with recommended installation way hubot-slack?

@joeyguerra
Copy link
Member

@hontarenko what mage are you currently using? What command do you run?

@hontarenko
Copy link


FROM node:20.12

ARG GITHUB_TOKEN
ARG HUBOT_SLACK_TOKEN


ENV GITHUB_TOKEN="${GITHUB_TOKEN}" \
    HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}"


RUN npm i -g yo@5.0.0 generator-hubot@2.0.1 && \
    addgroup hubot && \
    adduser --disabled-password --gecos '' --ingroup hubot hubot && \
    adduser hubot hubot

USER hubot

WORKDIR /home/hubot

RUN yo hubot --adapter=slack \
    --owner="test" \
    --name="HuBot" \
    --description="HuBot for github actions" \
    --defaults && \
    npm i axios@1.6.8

COPY trigger-workflow.js scripts/

CMD HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}" ./bin/hubot --adapter slack

Copy link

github-actions bot commented Apr 1, 2024

🎉 This issue has been resolved in version 2.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@joeyguerra
Copy link
Member

@hontarenko I pushed a fix for the issue. Please update your Dockerfile to install the latest generator-hubot and let me know.

Please note that I'm no longer maintaining this template. I recommend using npx hubot --create as described in the Hubot Readme.

@joeyguerra
Copy link
Member

joeyguerra commented Apr 1, 2024

If you're interested in using the latest version of Hubot and the new hubot-slack adapter that works with the latest version of Hubot, here's an updated Dockerfile for it:

Note: You'll need to create a new Slack app (you might be able to use your existing) and a Slack Bot Token. Here's the doc for it:

https://github.com/hubot-friends/hubot-slack


FROM node:21-alpine

ARG GITHUB_TOKEN
ARG HUBOT_SLACK_TOKEN


ENV GITHUB_TOKEN="${GITHUB_TOKEN}" \
    # HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}" \
    HUBOT_SLACK_APP_TOKEN="${HUBOT_SLACK_APP_TOKEN}" \
    HUBOT_SLACK_BOT_TOKEN="${HUBOT_SLACK_BOT_TOKEN}"


RUN addgroup hubot && \
    adduser --disabled-password --gecos '' --ingroup hubot hubot && \
    adduser hubot hubot

USER hubot

WORKDIR /home/hubot

# RUN yo hubot --adapter=slack \
#     --owner="test" \
#     --name="HuBot" \
#     --description="HuBot for github actions" \
#     --defaults && \
#     npm i axios@1.6.8
RUN npx hubot --create . --adapter @hubot-friends/hubot-slack --name "HuBot" && \
    npm i axios@1.6.8

COPY trigger-workflow.js scripts/

CMD HUBOT_SLACK_APP_TOKEN="${HUBOT_SLACK_APP_TOKEN}" HUBOT_SLACK_BOT_TOKEN="${HUBOT_SLACK_BOT_TOKEN}" npm start -- --name "HuBot"

@hontarenko
Copy link

@joeyguerra With latest version generator-hubot, i am getting an error:
image

./bin/hubot --adapter slack

@joeyguerra
Copy link
Member

@hontarenko I think that error is caused by using the latest version of Hubot (which is installed by the yeoman Hubot generator) and the old Slack Adapter (which is incompatible with the latest version of Hubot).

I think your options are to downgrade Hubot and all of the default Hubot scripts or update to the compatible Slack Adapter (which requires you to get a Slack app token AND a Slack Bot Token https://github.com/hubot-friends/hubot-slack).

I think you can downgrade Hubot and it's default scripts with the following:

In your original version Dockerfile:

RUN yo hubot --adapter=slack \
    --owner="test" \
    --name="HuBot" \
    --description="HuBot for github actions" \
    --defaults && \
    npm i axios@1.6.8 hubot@4 hubot-redis-brain@2 hubot-diagnostics@1

Looking forward to hearing what path you take.

@hontarenko
Copy link

@joeyguerra With downgraded versions i got dependency conflict:

image

And if using --force: {"level":50,"time":1712071439122,"pid":93,"hostname":"40391f503aab","name":"HuBot","msg":"Cannot load adapter slack - Error: Cannot find module 'hubot-slack'\nRequire stack:\n- /home/hubot/node_modules/hubot/src/robot.js\n- /home/hubot/node_modules/hubot/es2015.js\n- /home/hubot/node_modules/hubot/index.js\n- /home/hubot/node_modules/hubot/bin/hubot.js\n- /home/hubot/node_modules/hubot/bin/hubot"}

@joeyguerra
Copy link
Member

Ok. --force might work. Looks like the error is because hubot-slack isn't installed. I suspect it's because the latest generator-hubot isn't installing it correctly.

Can you please try installing it:

RUN yo hubot --adapter=slack \
    --owner="test" \
    --name="HuBot" \
    --description="HuBot for github actions" \
    --defaults && \
    npm i axios@1.6.8 hubot@4 hubot-redis-brain@2 hubot-diagnostics@1 hubot-slack --force

@hontarenko
Copy link

@joeyguerra I got the same errors

@hontarenko
Copy link

I think trouble in this function https://github.com/hubotio/hubot/blob/main/src/Robot.mjs#L520-L522

@hontarenko
Copy link

{"level":50,"time":1712144903526,"pid":178,"hostname":"67f22d073dea","name":"HuBot","msg":"Cannot load adapter [no path set] slack - TypeError: (intermediate value).default.use is not a function"}
file:///home/hubot/node_modules/hubot/src/Robot.mjs:523
    return await (await import(adapterPath)).default.use(this)
                                                     ^

TypeError: (intermediate value).default.use is not a function
    at Robot.importAdapterFrom (file:///home/hubot/node_modules/hubot/src/Robot.mjs:523:54)
    at async Robot.requireAdapterFrom (file:///home/hubot/node_modules/hubot/src/Robot.mjs:519:12)
    at async Robot.loadAdapter (file:///home/hubot/node_modules/hubot/src/Robot.mjs:503:26)
    at async file:///home/hubot/node_modules/hubot/bin/Hubot.mjs:132:3

Node.js v20.12.0

@joeyguerra
Copy link
Member

That error suggests that Hubot version 4 is not being installed. The of the code you posted is in the newer versions of Hubot.

@joeyguerra
Copy link
Member

joeyguerra commented Apr 3, 2024

The following Dockerfile seems to work, but I still recommend you moving to the latest version of Hubot with the new Slack Adapter because the configuration defined below is using unmaintained versions of modules that have a possibility of not working together and won't get updated for any security vulnerabilities.

FROM node:20.12

ARG GITHUB_TOKEN
ARG HUBOT_SLACK_TOKEN

ENV GITHUB_TOKEN="${GITHUB_TOKEN}" \
    HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}"

RUN npm i -g yo generator-hubot && \
    addgroup hubot && \
    adduser --disabled-password --gecos '' --ingroup hubot hubot && \
    adduser hubot hubot

USER hubot

WORKDIR /home/hubot

RUN yo hubot --owner="test" \
    --name="HuBot" \
    --description="HuBot for github actions" \
    --defaults
RUN npm i axios@1.6.8 hubot@4 hubot-slack
RUN npm i hubot-redis-brain@2 hubot-diagnostics@1 coffeescript@1 --force
RUN rm scripts/Example.mjs

COPY trigger-workflow.js scripts/

CMD ["npm", "start", "--", "--adapter", "slack", "--name", "HuBot"]

@hontarenko
Copy link

Thanks! Problem solved :)

@joeyguerra
Copy link
Member

You're welcome. I'm curious, care to share what you're using Hubot for? Is it valuable?

@hontarenko
Copy link

We are using Hubot for triggering github actions workflows with different parameters

@joeyguerra
Copy link
Member

@hontarenko What makes it more attractive than just using the Github Actions UI?

@hontarenko
Copy link

Because I use slack integration with github to run github actions workflows from slack commands. Such a business need

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

Successfully merging a pull request may close this issue.

3 participants