|
2 | 2 | # Show some help to git noobies
|
3 | 3 | #
|
4 | 4 | # Dependencies:
|
5 |
| -# None |
| 5 | +# jsdom |
| 6 | +# jquery |
6 | 7 | #
|
7 | 8 | # Configuration:
|
8 | 9 | # None
|
|
11 | 12 | # git help <topic>
|
12 | 13 | #
|
13 | 14 | # Author:
|
14 |
| -# vquaiato |
15 |
| - |
16 |
| -module.exports = (robot) -> |
17 |
| - git_help = new Array() |
| 15 | +# vquaiato, Jens Jahnke |
18 | 16 |
|
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 |
20 | 18 |
|
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() |
24 | 22 |
|
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() |
28 | 32 |
|
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() |
30 | 36 |
|
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