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

[DSL] Migrate in some generic helper functions #80

Closed
orta opened this issue Jan 5, 2017 · 1 comment
Closed

[DSL] Migrate in some generic helper functions #80

orta opened this issue Jan 5, 2017 · 1 comment
Labels
enhancement You Can Do This This idea is well spec'd and ready for a PR

Comments

@orta
Copy link
Member

orta commented Jan 5, 2017

From jestjs/jest#2508

danger.github.linkFiles ->

// Takes a list of file paths, and converts it into clickable links
const linkableFiles = (paths: Array<string>): string => {
  const repoURL = danger.github.pr.head.repo.html_url;
  const ref = danger.github.pr.head.ref;
  const links = paths.map(path => {
    return createLink(`${repoURL}/blob/${ref}/${path}`, path);
  });
  return toSentence(links);
};

I think we probably also need util functions that are specific to universal Danger use-cases, mainly as the JS core lib is relatively weak:

danger.utils.sentence:

// ["1", "2", "3"] to "1, 2 and 3"
const toSentence = (array: Array<string>) : string => {
  if (array.length === 1) { return array[0]; }
  return array.slice(0, array.length - 1).join(', ') + ' and ' + array.pop();
};

danger.utils.href:

// ("/href/thing", "name") to "<a href="/href/thing">name</a>"
const createLink = (href: string, text: string): string => 
  `<a href='${href}'>${text}</a>`;
@orta orta added enhancement You Can Do This This idea is well spec'd and ready for a PR labels Jan 5, 2017
macklinu added a commit that referenced this issue Jan 31, 2017
Relates to #80

`danger.utils` includes two functions:

* `href(href: string, text: string): string`
* `sentence(array: Array<string>): string`
macklinu added a commit that referenced this issue Feb 1, 2017
Relates to #80

`danger.utils` includes two functions:

* `href(href: string, text: string): string`
* `sentence(array: Array<string>): string`
macklinu added a commit that referenced this issue Mar 17, 2017
Relates to #80

`danger.utils` includes two functions:

* `href(href: string, text: string): string`
* `sentence(array: Array<string>): string`
@orta
Copy link
Member Author

orta commented Mar 18, 2017

These are in 👍

@orta orta closed this as completed Mar 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement You Can Do This This idea is well spec'd and ready for a PR
Projects
None yet
Development

No branches or pull requests

1 participant