hubotio / generator-hubot

Hubot generator for Yeoman
MIT License
155 stars 91 forks source link

Prompts for inputs even when Arguments are passed #111

Closed datsabk closed 5 months ago

datsabk commented 6 months ago

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 commented 6 months ago

@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 commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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

joeyguerra commented 5 months ago

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

hontarenko commented 5 months ago

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

joeyguerra commented 5 months ago

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

hontarenko commented 5 months ago

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
github-actions[bot] commented 5 months ago

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

The release is available on:

Your semantic-release bot :package::rocket:

joeyguerra commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

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

./bin/hubot --adapter slack

joeyguerra commented 5 months ago

@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 commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

@joeyguerra I got the same errors

hontarenko commented 5 months ago

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

hontarenko commented 5 months ago
{"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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

Thanks! Problem solved :)

joeyguerra commented 5 months ago

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

hontarenko commented 5 months ago

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

joeyguerra commented 5 months ago

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

hontarenko commented 5 months ago

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