-
Notifications
You must be signed in to change notification settings - Fork 71
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
feat: Add optional project_name to action #755
feat: Add optional project_name to action #755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, @miguel-botelho thank you very much for your contribution and especially for implementing this so quickly!
if there's any way to find the name of the Pulumi project without the user specifying on the YML, I believe would be less intrusive
IMO, I think we can get the project name programmatically using the Automation API. The Project Settings have a field for the project name.
For example, we import items from the Automation API here.
You should be able to get an instance of ProjectSettings
using this method. I think this method is callable whenever, but you might want to wait until after this line so the stack is selected. Forgive me, I'm not very well-versed on the Automation API.
CHANGELOG.md
Outdated
@@ -9,6 +9,8 @@ | |||
|
|||
- feat: Always show login information | |||
|
|||
- feat: Add project name to avoid having unintended edited comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- feat: Add project name to avoid having unintended edited comments | |
- feat: Includes the project name in comments, eliminating conflicts when working with multiple projects in the same repository. ([#563](https://github.com/pulumi/actions/issues/563)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! Committed here: 905033c
src/libs/pr.ts
Outdated
let heading = `#### :tropical_drink: \`${command}\` on ${stackName}`; | ||
if (projectName) { | ||
heading = `${heading} for project ${projectName}` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Nit: Assume projectName
is set. Do you think the message would be clear enough if written as
#### :tropical_drink: \`${command}\` on ${projectName}/${stackName}`
...or do you think having for project ${projectName}
is necessary for clarity?
I'm leaning towards "not clear enough" but WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think projectName/stackName is enough IMO, if the name of the project is something indicative. Not sure what's the "norm" for Pulumi project names, but for the ones I use, the simpler output is better 😄
I ended up refactoring to be less verbose here: 905033c, but I can always change it back
Oh, I also wanted to say thanks for fixing up the tests too! |
Hey @RobbieMcKinstry , many thanks for the help and the quick review. I ended up passing the |
Another question, how can I test this development on one of my projects? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good!
Thanks for this, I'm sure people will love this addition! Especially the ones with mono-repos with multiple stacks :)
src/main.ts
Outdated
@@ -41,6 +41,8 @@ const main = async () => { | |||
? LocalWorkspace.createOrSelectStack(stackArgs, stackOpts) | |||
: LocalWorkspace.selectStack(stackArgs, stackOpts)); | |||
|
|||
config.projectName = (await stack.workspace.projectSettings()).name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should split this into two variables?
config.projectName = (await stack.workspace.projectSettings()).name; | |
const projectSettings = await stack.workspace.projectSettings(); | |
config.projectName = projectSettings.name; |
Something like that? Just to improve readability?
Maybe we should add an invariant as well? I'm not sure if we do any validation in projectSettings()
, so might not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just committed it here: 1f66ab8
I ended up not adding the invariant
as the name
property is required inside the ProjectSettings
object.
src/config.ts
Outdated
@@ -34,6 +34,7 @@ export const config = rt | |||
command: command, | |||
stackName: rt.String, | |||
workDir: rt.String, | |||
projectName: rt.String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can eliminate the projectName
input entirely by relying on this line below:
const projectSettings = await stack.workspace.projectSettings();
We should always be able to get the project name from the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the input part and did something similar to the isPullRequest
property inside the Config
object. Are you suggesting removing the projectName
entirely from the Config
object and pass it to the handlePullRequest
method in another parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, did you push that change? Right now, in the diff, I see the value in Config
is always set to the empty string.
My goal is to eliminate partially initialized states in the Config
object. As much as possible, that Config
object should be immutable:
- If at the time of construction, we can access the
projectName
, then that works. - But if not, I'd prefer passing the
projectName
field into the handlePullRequest` function.
From the diff I'm seeing, the config object is initialized with an empty string here and that value is overwritten here. I'd prefer if we could avoid this mutation.
Does that help? 😅 Sorry if that's unclear or inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I think it's easier to pass projectName as a field on the function as well (and also avoids having a variable with a different value, depending on time of calling). I'll look into it in a bit, commit the changes, and test it as well via the link you sent. I'll notify in here when I've tested it "for real" 👍
I think you can refer to the public URL and commit SHA (or branch name). |
9d869e5
to
0df7385
Compare
Hey @cobraz @RobbieMcKinstry 👋 Feel free to review it again and leave your feedback on this one 😄 |
Hey @RobbieMcKinstry , sorry for pinging you again, were you able to review this one? 🙏 |
Add project_name property as optional so that the comments created by the Github action are more unique, allowing monorepos with multiple projects to use the editCommentOnPr flag properly
This reverts commit eba3969.
43e3945
to
f0fd28e
Compare
3dbdb02
to
007f11b
Compare
Hey @RobbieMcKinstry , just rebased it with the most recent changes in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution! I appreciate your thoughtful effort in working through my requested changes and your patience and persistence after I went dark on review. Seriously, thank you @miguel-botelho! 🙇🏻
@miguel-botelho Would you be willing to send me an email at robbie@pulumi.com? I want to send a small thank-you gift from Pulumi for your contribution. |
Many thanks! I'll ping you there in a few minutes. Also, I'm the one that should be thanking for guiding me during the review phase 🙇 |
Hah, anytime, friend! |
This PR adds a new optional property called
project_name
, so that the comments created by the Github action are unique, based on currentstack_infra
+project_name
. This will facilitate working with Pulumi actions inside monorepos, so that multiple jobs are ran in a PR and each job will have its own comment, given they are for different stacks or projects.Besides that, also added a bit more tests around the pr spec.
On another note, I went with creating
project_name
as optional, not sure on what is the desired approach for this one. Also, if there's any way to find the name of the Pulumi project without the user specifying on the YML, I believe would be less intrusive (but I couldn't find by reading the project's source code a way to do so). Feedback is more than welcomed!Fixes #563