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 comment target flag and parsing #1241

Merged
merged 14 commits into from
Nov 9, 2022

Conversation

tasdomas
Copy link
Contributor

@tasdomas tasdomas commented Oct 28, 2022

One significant change in this PR is that bitbucket commit comments will no longer be automatically posted at the PR level.

The --target=auto scenario is not yet being handled in this PR, this will be implemented in a follow-up.

The general idea is as follows:

  • legacy comment target flags (--pr, --commitSha) take precendence.
  • the --issue flag will be removed in a follow-up (replaced with --target=issue#id)
  • the --target flag can take both qualified (--target=pr#id or --target=commit#sha or --target=issue#id) and unqualified values (--target=pr or --target=commit)
  • when parsing an unqualified pr target, cml will first attempt to determine the PR number using the forge context (env vars for bitbucket and gitlab, context.pull_request.number for github) - if that fails, an attempt will be made to determine the pr number using the sha of the head commit
  • when parsing an unqualified commit target, comments will be attached to the head commit

@tasdomas tasdomas temporarily deployed to internal October 28, 2022 14:03 Inactive
@tasdomas tasdomas marked this pull request as draft October 28, 2022 14:07
@tasdomas tasdomas force-pushed the d009-comment-target branch from 3851bb2 to 5b1deb4 Compare October 28, 2022 14:08
@tasdomas tasdomas temporarily deployed to internal October 28, 2022 14:08 Inactive
@tasdomas tasdomas marked this pull request as ready for review November 3, 2022 06:08
The flag is replaced with --target=issue#<id>.
--target=auto will create PR comments if the comment is run in an action with a PR context
or if the HEAD commit is associated with a PR. Otherwise a commit comment will be created.
@tasdomas tasdomas temporarily deployed to internal November 3, 2022 09:46 Inactive
@tasdomas tasdomas temporarily deployed to internal November 3, 2022 10:47 Inactive
@tasdomas tasdomas temporarily deployed to internal November 3, 2022 11:33 Inactive
@tasdomas tasdomas temporarily deployed to internal November 3, 2022 17:43 Inactive
@dacbd
Copy link
Contributor

dacbd commented Nov 3, 2022

This portion is to just add the --target=commit type functionality? and not --target=issue#1234 type correct?

@tasdomas
Copy link
Contributor Author

tasdomas commented Nov 3, 2022 via email

dacbd
dacbd previously requested changes Nov 3, 2022
Copy link
Contributor

@dacbd dacbd left a comment

Choose a reason for hiding this comment

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

@tasdomas tasdomas temporarily deployed to internal November 3, 2022 21:52 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2022

Test Comment

CML watermark

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2022

Test Comment

CML watermark

@tasdomas
Copy link
Contributor Author

tasdomas commented Nov 4, 2022

using a --target=issue#1234 creates commit comment. see: https://github.com/iterative/cml-playground/actions/runs/3388499291/jobs/5630555691#step:5:11

Fixed.

Copy link
Contributor

@DavidGOrtega DavidGOrtega left a comment

Choose a reason for hiding this comment

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

One significant change in this PR is that bitbucket commit comments will no longer be automatically posted at the PR level.

Why? It goes against the current CML definition (the video is even showing it as the rest of forges)

@tasdomas
Copy link
Contributor Author

tasdomas commented Nov 4, 2022

One significant change in this PR is that bitbucket commit comments will no longer be automatically posted at the PR level.

Why? It goes against the current CML definition (the video is even showing it as the rest of forges)

Because this behavior is inconsistent across forges. We don't do the same thing for github, where the support for commit comments is similar to bitbucket's. In addition to this, the side effect of the current implementation is that the PR comments are augmented with a link to the commit on all forges, which imho is unnecessary.

@tasdomas tasdomas mentioned this pull request Nov 4, 2022
4 tasks
@github-actions

This comment was marked as resolved.

bin/cml/comment/create.js Outdated Show resolved Hide resolved
type: 'string',
description:
'Forge object to create comment on, can be one of pr, commit or issue. ' +
"Specify 'issue#123' to create a comment on a specific issue. " +
Copy link
Contributor

@casperdcl casperdcl Nov 8, 2022

Choose a reason for hiding this comment

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

what syntaxes are supported?

  • 123
  • #123
  • issue#123
  • pr#123
  • mr#123
  • URL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid targets are:

  • auto determine comment target automatically:
    • PR if running in a PR context
    • PR if HEAD commit is part of a PR
    • HEAD commit (fallback)
  • pr - determine pr by context or head commit (making allowances for how github's PR merge commits)
  • pr#123 - specific PR number
  • commit - current HEAD commit
  • commit#adfa12 - specific commit
  • issue#123 - specific issue

Copy link
Contributor

@casperdcl casperdcl Nov 16, 2022

Choose a reason for hiding this comment

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

I think we need:

  • #123 to auto-infer pr-or-issue
  • mr alias for pr
  • mr#123 alias for pr#123
  • why do we have commit#d34db3? Doesn't --commit-sha=d34db3 already cover this?
  • full URL (e.g. if they want to target another PR returned by cml pr)

moved to #1228 (review)

@tasdomas tasdomas temporarily deployed to internal November 9, 2022 09:53 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

Test Comment

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

Test Comment

@tasdomas
Copy link
Contributor Author

tasdomas commented Nov 9, 2022

One significant change in this PR is that bitbucket commit comments will no longer be automatically posted at the PR level.

Why? It goes against the current CML definition (the video is even showing it as the rest of forges)

Can we close this change request?

@tasdomas tasdomas self-assigned this Nov 9, 2022
@0x2b3bfa0 0x2b3bfa0 changed the title Add comment target flag and parsing. Add comment target flag and parsing Nov 9, 2022
Copy link
Contributor

@DavidGOrtega DavidGOrtega left a comment

Choose a reason for hiding this comment

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

👋 great effort!
I do not get the warn method.
It should be at most a CML capability and to be honest not even that. We already have a logging mechanism in place.
Its also missing in GH?

Probably I missing something 🙏

src/cml.js Outdated Show resolved Hide resolved
src/cml.js Show resolved Hide resolved
src/commenttarget.js Outdated Show resolved Hide resolved
src/drivers/bitbucket_cloud.js Outdated Show resolved Hide resolved
src/drivers/gitlab.js Outdated Show resolved Hide resolved
@0x2b3bfa0
Copy link
Member

I do not get the warn method.
It should be at most a CML capability and to be honest not even that. We already have a logging mechanism in place.
Its also missing in GH?

The warn method is meant to display warnings in the forge user interface, rather than just in the logs. It augments functionality supplied by winston.log but doesn't replace it. See #1227 (comment) for context.

@DavidGOrtega
Copy link
Contributor

DavidGOrtega commented Nov 9, 2022

The warn method is meant to display warnings in the forge user interface, rather than just in the logs.

But its doing at the end a console.log so could winston handle it?

@tasdomas tasdomas temporarily deployed to internal November 9, 2022 13:34 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

Test Comment

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

Test Comment

@0x2b3bfa0
Copy link
Member

But its doing at the end a console.log so could winston handle it?

Yes, except for GitHub, see my review suggestions above

@0x2b3bfa0 0x2b3bfa0 dismissed dacbd’s stale review November 9, 2022 15:26

Resolved with cacae963b9bbfe748f2c128896452a2aa32f04beb

Copy link
Contributor

@dacbd dacbd left a comment

Choose a reason for hiding this comment

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

final testing to be done in the feature branch

@tasdomas tasdomas merged commit dd911b1 into feature-comment-target Nov 9, 2022
@tasdomas tasdomas deleted the d009-comment-target branch November 9, 2022 17:39
tasdomas added a commit that referenced this pull request Dec 15, 2022
* Allow creation of issue comments in cml (#1202)

* Driver support for issue comments.

* Create or update issue comments.

* Add e2e issue comment creation tests for github and bitbucket drivers.

* Add gitlab issue comment e2e test.

* Add comment target flag and parsing (#1241)

* Add target cli option.

* Add comment target parsing.

* Add debug logging in comment target parsing.

Co-authored-by: DavidGOrtega <[email protected]>
Co-authored-by: Casper da Costa-Luis <[email protected]>
@dacbd dacbd mentioned this pull request Feb 17, 2023
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.

5 participants