generator-hubot icon indicating copy to clipboard operation
generator-hubot copied to clipboard

Prompts for inputs even when Arguments are passed

Open datsabk opened this issue 1 year ago • 3 comments

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.

datsabk avatar Feb 28 '24 20:02 datsabk

@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.

joeyguerra avatar Feb 28 '24 21:02 joeyguerra

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?

datsabk avatar Feb 28 '24 21:02 datsabk

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.

joeyguerra avatar Feb 28 '24 21:02 joeyguerra

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

hontarenko avatar Apr 01 '24 06:04 hontarenko

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

joeyguerra avatar Apr 01 '24 12:04 joeyguerra

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

hontarenko avatar Apr 01 '24 12:04 hontarenko

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

joeyguerra avatar Apr 01 '24 13:04 joeyguerra


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 [email protected] [email protected] && \
    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 [email protected]

COPY trigger-workflow.js scripts/

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

hontarenko avatar Apr 01 '24 13:04 hontarenko

:tada: This issue has been resolved in version 2.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Apr 01 '24 16:04 github-actions[bot]

@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 avatar Apr 01 '24 16:04 joeyguerra

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 [email protected]
RUN npx hubot --create . --adapter @hubot-friends/hubot-slack --name "HuBot" && \
    npm i [email protected]

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"

joeyguerra avatar Apr 01 '24 18:04 joeyguerra

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

./bin/hubot --adapter slack

hontarenko avatar Apr 02 '24 08:04 hontarenko

@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 [email protected] hubot@4 hubot-redis-brain@2 hubot-diagnostics@1

Looking forward to hearing what path you take.

joeyguerra avatar Apr 02 '24 14:04 joeyguerra

@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"}

hontarenko avatar Apr 02 '24 17:04 hontarenko

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 [email protected] hubot@4 hubot-redis-brain@2 hubot-diagnostics@1 hubot-slack --force

joeyguerra avatar Apr 02 '24 20:04 joeyguerra

@joeyguerra I got the same errors

hontarenko avatar Apr 03 '24 06:04 hontarenko

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

hontarenko avatar Apr 03 '24 11:04 hontarenko

{"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

hontarenko avatar Apr 03 '24 11:04 hontarenko

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 avatar Apr 03 '24 14:04 joeyguerra

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 [email protected] 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"]

joeyguerra avatar Apr 03 '24 15:04 joeyguerra

Thanks! Problem solved :)

hontarenko avatar Apr 03 '24 19:04 hontarenko

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

joeyguerra avatar Apr 03 '24 21:04 joeyguerra

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

hontarenko avatar Apr 04 '24 11:04 hontarenko

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

joeyguerra avatar Apr 04 '24 17:04 joeyguerra

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

hontarenko avatar Apr 05 '24 07:04 hontarenko