Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 1924f8d

Browse files
author
Tom Bell
committed
Merge pull request #882 from jan0sch/git-help
Refactored git-help script.
2 parents 8215b1d + 6872c5a commit 1924f8d

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/scripts/git-help.coffee

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Show some help to git noobies
33
#
44
# Dependencies:
5-
# None
5+
# jsdom
6+
# jquery
67
#
78
# Configuration:
89
# None
@@ -11,32 +12,31 @@
1112
# git help <topic>
1213
#
1314
# Author:
14-
# vquaiato
15-
16-
module.exports = (robot) ->
17-
git_help = new Array()
15+
# vquaiato, Jens Jahnke
1816

19-
git_help["create"] = "create a new repository -> git init\nclone local repository -> git clone /path/to/repository\nclone remote repository -> git clone username@host:/path/to/repository"
17+
jsdom = require("jsdom").jsdom
2018

21-
git_help["clone"] = git_help["create"]
22-
23-
git_help["add"] = "add changes to INDEX -> git add <filename>\nadd all changes to INDEX -> git add * \nremove or delete -> git rm <filename>"
19+
module.exports = (robot) ->
20+
robot.respond /git help (.+)$/i, (msg) ->
21+
topic = msg.match[1].toLowerCase()
2422

25-
git_help["remove"] = git_help["add"]
26-
27-
git_help["commit"] = "commit changes -> git commit -m \"Commit message\"\npush changes to remote repository -> git push origin master\nconnect local repository to remote repository -> git remote add origin <server>\nupdate local repository with remote changes -> git pull"
23+
url = 'http://git-scm.com/docs/git-' + topic
24+
msg.http(url).get() (err, res, body) ->
25+
window = (jsdom body, null,
26+
features:
27+
FetchExternalResources: false
28+
ProcessExternalResources: false
29+
MutationEvents: false
30+
QuerySelector: false
31+
).createWindow()
2832

29-
git_help["synchronize"] = git_help["commit"]
33+
$ = require("jquery").create(window)
34+
name = $.trim $('#header .sectionbody .paragraph').text()
35+
desc = $.trim $('#_synopsis + .sectionbody').text()
3036

31-
git_help["branch"] = "create new branch -> git checkout -b <name>\nswitch to master branch -> git checkout master\ndelete branch -> git branch -d <name>\npush branch to remote repository -> git push origin <branch name>"
32-
33-
git_help["merge"] = "merge changes from another branch -> git merge <branch>\nview changes between two branches -> git diff <source branch> <target branch>"
34-
35-
git_help["tag"] = "create tag -> git tag <tag name> <commit ID>\nget commit IDs -> git log"
36-
37-
git_help["restore"] = "replace working copy with latest from HEAD -> git checkout --<file name>"
38-
39-
robot.hear /^git help (create|clone|add|remove|commit|synchronize|branch|merge|tag|restore)$/i, (msg) ->
40-
help = git_help[msg.match[1]]
41-
42-
msg.send help
37+
if name and desc
38+
msg.send name
39+
msg.send desc
40+
msg.send "See #{url} for details."
41+
else
42+
msg.send "No git help page found for #{topic}."

0 commit comments

Comments
 (0)