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

[WIP] Support inline comments #99

Closed
wants to merge 7 commits into from
Closed

[WIP] Support inline comments #99

wants to merge 7 commits into from

Conversation

macklinu
Copy link
Member

Resolves #77

This is a work-in-progress for #77. I've been sitting on this commit and wanted to get it pushed up and ask some questions about the API and if I'm heading in the right direction before digging in deeper.

TODO:

  • add changelog entry with example of how to use
  • update API documentation (in interfaces like DangerContext)
  • create a comment on a specific file/line of a commit in GitHub

@DangerCI
Copy link

DangerCI commented Jan 14, 2017

Warnings
⚠️ Please add a changelog entry for your changes.

Generated by 🚫 dangerJS

Copy link
Member Author

@macklinu macklinu left a comment

Choose a reason for hiding this comment

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

Some initial thoughts


/**
* Puts a message inside the Danger table
*
* @param {MarkdownString} message the String to output
*/
markdown(message: MarkdownString): void
markdown(message: MarkdownString, options?: DangerOptions): void
Copy link
Member Author

Choose a reason for hiding this comment

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

markdown() should support { file, line } options too, right?

Copy link
Member

Choose a reason for hiding this comment

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

I think so, I can see there are good reasons for wanting to put arbitrary markdown on a file 👍

const fail = (message: MarkdownString) => results.fails.push({ message })
const warn = (message: MarkdownString) => results.warnings.push({ message })
const message = (message: MarkdownString) => results.messages.push({ message })
const markdown = (message: MarkdownString) => results.markdowns.push(message)
Copy link
Member Author

Choose a reason for hiding this comment

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

results.markdowns: Array differs in that it currently accepts MarkdownString as its type, whereas fails, warns, and messages accept Violation as its type. To keep parity with the Danger-rb API, markdown() should be able to accept { file, line } options, so I believe moving markdowns from Array<MarkdownString> to Array<Violation> is the appropriate change.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this makes sense 👍

@@ -84,6 +84,7 @@ export class Executor {
console.log("Found some message, writing it down")
}
const comment = githubResultsTemplate(results)
// TODO filter out Danger items that contain file/line info
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is the area where we could filter out results that contained a complete { file, line } object and make inline comments. if { file, line } is incomplete/missing, add them to the main Danger comment (I think this refers to your abstractions comment in #77 (comment), @orta).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is where you want to find:

  • Things with no file/line (main comment)
  • Things with file/line inside the diff (inline)
  • Things with file/line outside the diff (main comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

This function only accepts the results: DangerResults. I'm thinking we will need the context: DangerContext (or at least danger: DangerDSLType), so that we can call danger.git.diffForFile(violation.options.file) and determine if the { file, line } supplied are valid for creating an inline comment. Does that make sense?

export function template(results: DangerResults): string {
return `
${table("Fails", "no_entry_sign", results.fails)}
${table("Warnings", "warning", results.warnings)}
${table("Messages", "book", results.messages)}
${results.markdowns.join("\n\n")}
${table("Markdowns", "information_source", results.markdowns)}
Copy link
Member Author

Choose a reason for hiding this comment

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

information_source = ℹ️

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'm going to change this back to just displaying markdown as it's provided, based on this comment - #109 (comment).

Copy link
Member

@orta orta left a comment

Choose a reason for hiding this comment

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

Yeah, this feels like a good start


/**
* Puts a message inside the Danger table
*
* @param {MarkdownString} message the String to output
*/
markdown(message: MarkdownString): void
markdown(message: MarkdownString, options?: DangerOptions): void
Copy link
Member

Choose a reason for hiding this comment

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

I think so, I can see there are good reasons for wanting to put arbitrary markdown on a file 👍

const fail = (message: MarkdownString) => results.fails.push({ message })
const warn = (message: MarkdownString) => results.warnings.push({ message })
const message = (message: MarkdownString) => results.messages.push({ message })
const markdown = (message: MarkdownString) => results.markdowns.push(message)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this makes sense 👍

@@ -48,6 +48,11 @@ export interface DangerContext {
results: DangerResults
}

export interface DangerOptions {
Copy link
Member

Choose a reason for hiding this comment

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

maybe MessagingOptions ?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a better name, will update. 👍

@@ -84,6 +84,7 @@ export class Executor {
console.log("Found some message, writing it down")
}
const comment = githubResultsTemplate(results)
// TODO filter out Danger items that contain file/line info
Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is where you want to find:

  • Things with no file/line (main comment)
  • Things with file/line inside the diff (inline)
  • Things with file/line outside the diff (main comment)

export function template(results: DangerResults): string {
return `
${table("Fails", "no_entry_sign", results.fails)}
${table("Warnings", "warning", results.warnings)}
${table("Messages", "book", results.messages)}
${results.markdowns.join("\n\n")}
${table("Markdowns", "information_source", results.markdowns)}
Copy link
Member

Choose a reason for hiding this comment

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

👍

@macklinu
Copy link
Member Author

I haven't forgotten about this PR. Been focused on client work recently but should have more time to devote to this feature during the rest of this week/weekend. 👨‍💻

@orta
Copy link
Member

orta commented Jan 19, 2017

Sidenote: here is an amazing example of inlining on to the main comment ( https://twitter.com/tivac/status/821994608984924160 )with syntax highlighting etc

@macklinu
Copy link
Member Author

This PR has been sitting here and I haven't gotten a chance to devote serious time to it since early January. I'm going to close this for now and leave #77 open for someone to pick up if they'd like to. I'll comment on the issue if I dive back into it, but this is a desirable feature that I don't want to hold up if someone has more time to work on it.

@macklinu macklinu closed this Mar 21, 2017
@macklinu macklinu mentioned this pull request Mar 21, 2017
@orta orta deleted the 77-inline-comments branch March 21, 2017 14:34
@orta
Copy link
Member

orta commented Mar 21, 2017

👍

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.

3 participants