Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Enable date formatting #626

Merged
merged 2 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@

Since this is a **TypeScript** project, we have to compile the code before running it.

First, if you haven't already done so, run npm install:
First, if you haven't already done so, install dependencies and create a sym link:

- `npm install`
- `[sudo] npm link`

To run **incrementally** in watch mode:

- `npm run build:watch`
- `npm run dev`

To run **once**:

Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ gh pull-request
| `-m`, `--me` | _Optional_ | `Boolean` |
| `-d`, `--detailed` | _Optional_ | `Boolean` |
| `--direction` | _Optional_ | [`asc`, `desc`] |
| `--date` | _Optional_ | `String` |
| `-b`, `--branch` | _Optional_ | `String` |
| `--remote` | _Optional_ | `String` |
| `-r`, `--repo` | _Optional_ | `String` |
Expand Down Expand Up @@ -198,6 +199,12 @@ gh pr --list --sort complexity
gh pr --list --link
```

- List open pull requests with a formatted date (_Any string that the moment library's formatter accepts should work: https://momentjs.com/docs/#/displaying/format/_).

```
gh pr --list --date "dddd, MMMM Do YYYY, h:mm:ss a"
```

### 3. Fetch

| Option | Usage | Type |
Expand Down Expand Up @@ -411,6 +418,7 @@ gh notification
| `--remote` | _Optional_ | `String` |
| `-r`, `--repo` | _Optional_ | `String` |
| `-u`, `--user` | _Optional_ | `String` |
| `--date` | _Optional_ | `String` |

#### Examples

Expand All @@ -426,6 +434,12 @@ gh nt
gh nt --latest --user eduardolundgren --repo node-gh
```

- Diplay notifications with a formatted date (_Any string that the moment library's formatter accepts should work: https://momentjs.com/docs/#/displaying/format/_).

```
gh nt --date "dddd, MMMM Do YYYY, h:mm:ss a"
```

### 2. Watch

| Option | Usage | Type |
Expand Down Expand Up @@ -570,6 +584,7 @@ gh is 1 --close --user eduardolundgren
| `-l`, `--list` | **Required** | `Boolean` |
| `-a`, `--all` | _Optional_ | `Boolean` |
| `-A`, `--assignee` | _Optional_ | `String` |
| `--date` | _Optional_ | `String` |
| `-d`, `--detailed` | _Optional_ | `Boolean` |
| `-L`, `--label` | _Optional_ | `String` |
| `-M`, `--milestone` | _Optional_ | [`Number`, `String`] |
Expand Down Expand Up @@ -610,6 +625,12 @@ gh is --list --detailed
gh is --list --state closed
```

- List issues with a formatted date (_Any string that the moment library's formatter accepts should work: https://momentjs.com/docs/#/displaying/format/_).

```
gh is --list --date "dddd, MMMM Do YYYY, h:mm:ss a"
```

- List issues filtered by milestone.

```
Expand Down Expand Up @@ -755,6 +776,7 @@ gh re --browser --user eduardolundgren --repo node-gh
| `-d`, `--detailed` | _Optional_ | `Boolean` |
| `-u`, `--user` | _Optional_ | `String` |
| `-t`, `--type` | _Optional_ | [`all`, `owner`, `public`, `private`, `member`] |
| `--date` | _Optional_ | `String` |

#### Examples

Expand All @@ -776,6 +798,12 @@ gh re --list --type private
gh re --list --user zenorocha
```

- List open repositories with a formatted date (_Any string that the moment library's formatter accepts should work: https://momentjs.com/docs/#/displaying/format/_).

```
gh re --list --detailed --date "dddd, MMMM Do YYYY, h:mm:ss a"
```

### 3. Create

| Option | Usage | Type |
Expand Down Expand Up @@ -1010,6 +1038,7 @@ gh gi --browser --id 5991877
| -------------- | ------------ | --------- |
| `-l`, `--list` | **Required** | `Boolean` |
| `-u`, `--user` | _Optional_ | `String` |
| `--date` | _Optional_ | `String` |

#### Examples

Expand All @@ -1025,6 +1054,12 @@ gh gi --list
gh gi --list --user brunocoelho
```

- List gists with a formatted date (_Any string that the moment library's formatter accepts should work: https://momentjs.com/docs/#/displaying/format/_).

```
gh gi --list --date "dddd, MMMM Do YYYY, h:mm:ss a"
```

### 3. Create

| Option | Usage | Type |
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"dev": "tsc --watch",
"commit": "git-cz",
"format": "prettier 'lib/**/*.js' && prettier 'bin/*.js'",
"env:test": "cross-env NODE_ENV=testing GH_USER=protoEvangelion GH_TOKEN=0001",
Expand Down
9 changes: 4 additions & 5 deletions src/cmds/gists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Gists.DETAILS = {
options: {
browser: Boolean,
content: String,
date: String,
delete: [String, Array],
description: String,
fork: String,
Expand Down Expand Up @@ -219,11 +220,9 @@ Gists.prototype.listCallback_ = function(err, gists, opt_callback) {

if (gists && gists.length > 0) {
gists.forEach(gist => {
logger.log(
`${logger.colors.yellow(`${gist.owner.login}/${gist.id}`)} ${logger.getDuration(
gist.updated_at
)}`
)
const duration = logger.getDuration(gist.updated_at, options.date)

logger.log(`${logger.colors.yellow(`${gist.owner.login}/${gist.id}`)} ${duration}`)

if (gist.description) {
logger.log(gist.description)
Expand Down
9 changes: 5 additions & 4 deletions src/cmds/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Issue.DETAILS = {
browser: Boolean,
close: Boolean,
comment: String,
date: String,
detailed: Boolean,
label: String,
list: Boolean,
Expand Down Expand Up @@ -439,7 +440,7 @@ Issue.prototype.list = function(user, repo, opt_callback) {
})

if (issues && issues.length > 0) {
const formattedIssues = formatIssues(issues, options.detailed)
const formattedIssues = formatIssues(issues, options.detailed, options.date)

logger.log(formattedIssues)
} else {
Expand Down Expand Up @@ -552,7 +553,7 @@ Issue.prototype.search = function(user, repo, opt_callback, options) {
})

if (issues && issues.length > 0) {
var formattedIssues = formatIssues(issues, options.detailed)
var formattedIssues = formatIssues(issues, options.detailed, options.date)

logger.log(formattedIssues)
} else {
Expand All @@ -563,7 +564,7 @@ Issue.prototype.search = function(user, repo, opt_callback, options) {
})
}

function formatIssues(issues, showDetailed) {
function formatIssues(issues, showDetailed, dateFormatter?: string) {
issues.sort((a, b) => {
return a.number > b.number ? -1 : 1
})
Expand All @@ -572,7 +573,7 @@ function formatIssues(issues, showDetailed) {
const formattedIssuesArr = issues.map(issue => {
const issueNumber = logger.colors.green(`#${issue.number}`)
const issueUser = logger.colors.magenta(`@${issue.user.login}`)
const issueDate = `(${logger.getDuration(issue.created_at)})`
const issueDate = `(${logger.getDuration(issue.created_at, dateFormatter)})`

let formattedIssue = `${issueNumber} ${issue.title} ${issueUser} ${issueDate}`

Expand Down
5 changes: 4 additions & 1 deletion src/cmds/milestone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Milestone.DETAILS = {
commands: ['list'],
options: {
all: Boolean,
date: String,
organization: String,
list: Boolean,
},
Expand Down Expand Up @@ -102,7 +103,9 @@ Milestone.prototype.list = function(user, repo, opt_callback) {

if (milestones && milestones.length > 0) {
milestones.forEach(milestone => {
const due = milestone.due_on ? logger.getDuration(milestone.due_on) : 'n/a'
const due = milestone.due_on
? logger.getDuration(milestone.due_on, options.date)
: 'n/a'
const description = milestone.description || ''
const title = logger.colors.green(milestone.title)
const state = logger.colors.magenta(`@${milestone.state} (due ${due})`)
Expand Down
6 changes: 5 additions & 1 deletion src/cmds/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Notifications.DETAILS = {
description: 'Provides a set of util commands to work with Notifications.',
commands: ['latest', 'watch'],
options: {
date: String,
latest: Boolean,
remote: String,
repo: String,
Expand Down Expand Up @@ -121,7 +122,10 @@ Notifications.prototype.latest = function(opt_watch, done) {
logger.log(
`${logger.colors.magenta(`@${event.actor.login}`)} ${
event.txt
} ${logger.colors.cyan(options.repo)} ${logger.getDuration(event.created_at)}`
} ${logger.colors.cyan(options.repo)} ${logger.getDuration(
event.created_at,
options.date
)}`
)
})
}
Expand Down
10 changes: 6 additions & 4 deletions src/cmds/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PullRequest.DETAILS = {
browser: Boolean,
close: Boolean,
comment: String,
date: String,
description: String,
detailed: Boolean,
direction: String,
Expand Down Expand Up @@ -509,7 +510,8 @@ PullRequest.prototype.printPullsInfoTable_ = function(pulls) {
pulls.forEach(pull => {
const { createdTime, number, prInfo, user, status } = getColorizedFields(
pull,
isCompact ? getTotalWidth() : tableWidths[1]
isCompact ? getTotalWidth() : tableWidths[1],
options.date
)

const body: TCell = [
Expand All @@ -534,8 +536,8 @@ PullRequest.prototype.printPullsInfoTable_ = function(pulls) {
return table.toString()
}

function getColorizedFields(pull, length) {
const createdTime = logger.getDuration(pull.created_at)
function getColorizedFields(pull, length, dateFormatter) {
const createdTime = logger.getDuration(pull.created_at, dateFormatter)
const number = logger.colors.green(`#${pull.number}`)
const prInfo = formatPrInfo(pull, length)
const user = logger.colors.magenta(`@${pull.user.login}`)
Expand Down Expand Up @@ -637,7 +639,7 @@ PullRequest.prototype.printPullInfo_ = function(pull) {

var headline = `${logger.colors.green(`#${pull.number}`)} ${pull.title} ${logger.colors.magenta(
`@${pull.user.login}`
)} (${logger.getDuration(pull.created_at)})${status}`
)} (${logger.getDuration(pull.created_at, options.date)})${status}`

if (options.link) {
headline += ` ${logger.colors.blue(pull.html_url)}`
Expand Down
3 changes: 2 additions & 1 deletion src/cmds/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Repo.DETAILS = {
browser: Boolean,
clone: Boolean,
color: String,
date: String,
delete: String,
description: String,
detailed: Boolean,
Expand Down Expand Up @@ -492,7 +493,7 @@ Repo.prototype.listCallback_ = function(err, repos, opt_callback) {
logger.log(logger.colors.blue(repo.homepage))
}

logger.log(`last update ${logger.getDuration(repo.updated_at)}`)
logger.log(`last update ${logger.getDuration(repo.updated_at, options.date)}`)
}

if (options.isTTY.out) {
Expand Down
13 changes: 9 additions & 4 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ export function log(...args) {
console.log(...args)
}

export function getDuration(start, opt_end?) {
if (!opt_end) {
opt_end = testing ? '2018-10-10T16:00:00Z' : Date.now()
export function getDuration(start, formatter?) {
if (testing) {
return moment(start).from('2018-10-10T16:00:00Z')
}
return moment.duration(moment(start).diff(opt_end)).humanize(true)

if (formatter) {
return moment(start).format(formatter)
}

return moment(start).fromNow()
}

export function applyReplacements(output, replaceMap?: object) {
Expand Down