{"action":"created","comment":{"url":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments/130197965","pull_request_review_id":53052243,"id":130197965,"diff_hunk":"@@ -0,0 +1,167 @@\n+// Copyright (c) 2016-2017 Chef Software Inc. and/or applicable contributors\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+use std::str::FromStr;\n+use std::path::Path;\n+use std::io;\n+use std::fs;\n+\n+use error::Result;\n+\n+use hcore::crypto::init;\n+use hcore::package::PackageIdent;\n+use common::ui::{UI, Status};\n+\n+// Check to see if the --scaffolding passed matches available core scaffolding\n+// If not check if we've been given a pkg ident for a custom scaffolding\n+pub fn scaffold_check(ui: &mut UI, maybe_scaffold: Option<&str>) -> Result<Option<PackageIdent>> {\n+    match maybe_scaffold {\n+        Some(scaffold) => {\n+            init();\n+            match scaffold {\n+                \"core/scaffolding-ruby\" |\n+                \"ruby\" |\n+                \"rails\" |\n+                \"RUBY\" |\n+                \"ruby-scaffolding\" => {\n+                    let ident = PackageIdent::from_str(\"core/scaffolding-ruby\")?;\n+                    let _ = ui.status(Status::Using, &format!(\"ruby scaffolding '{}'\", ident));\n+                    Ok(Some(ident))\n+                }\n+                \"core/scaffolding-go\" |\n+                \"go\" |\n+                \"golang\" |\n+                \"GO\" |\n+                \"go-scaffolding\" => {\n+                    let ident = PackageIdent::from_str(\"core/scaffolding-go\")?;\n+                    let _ = ui.status(Status::Using, &format!(\"go scaffolding '{}'\", ident));\n+                    Ok(Some(ident))\n+                }\n+                \"core/scaffolding-node\" |\n+                \"node\" |\n+                \"node.js\" |\n+                \"javascript\" |\n+                \"js\" => {\n+                    let ident = PackageIdent::from_str(\"core/scaffolding-node\")?;\n+                    let _ = ui.status(Status::Using, &format!(\"node scaffolding '{}'\", ident));\n+                    Ok(Some(ident))\n+                }\n+                _ => {\n+                    let ident = PackageIdent::from_str(scaffold)?;\n+                    let _ = ui.status(Status::Using, &format!(\"custom scaffolding: '{}'\", ident));\n+                    Ok(Some(ident))\n+                }\n+            }\n+        }\n+        // If nothing was passed try to autodiscover the codebase\n+        // I'm not saying it's magic. But, MAGIC.\n+        None => magic_function(ui),\n+    }\n+}\n+fn magic_function(ui: &mut UI) -> Result<Option<PackageIdent>> {\n+    // Determine if the current dir has an app that can use\n+    // one of our scaffoldings and use it by default\n+    try!(ui.begin(\"Attempting autodiscovery \"));\n+    try!(ui.para(\n+        \"No scaffolding type was provided. Let's see if we can figure out \\\n+        what kind of application you're planning to package.\",\n+    ));\n+    let current_path = Path::new(\".\");\n+    if is_project_ruby(&current_path) {\n+        let ident = PackageIdent::from_str(\"core/scaffolding-ruby\")?;\n+        try!(ui.begin(\"We've detected your app as Ruby\"));\n+        let _ = ui.status(Status::Using, &format!(\"scaffolding package: '{}'\", ident));\n+        try!(ui.para(\"\"));\n+        Ok(Some(ident))\n+    } else if is_project_golang(&current_path) {\n+        let ident = PackageIdent::from_str(\"core/scaffolding-go\")?;\n+        try!(ui.begin(\"We've detected your app as Golang\"));\n+        let _ = ui.status(Status::Using, &format!(\"scaffolding package: '{}'\", ident));\n+        try!(ui.para(\"\"));\n+        Ok(Some(ident))\n+    } else if is_project_node(&current_path) {\n+        let ident = PackageIdent::from_str(\"core/scaffolding-node\")?;\n+        try!(ui.begin(\"We've detected your app as Node.js\"));\n+        let _ = ui.status(Status::Using, &format!(\"scaffolding package: '{}'\", ident));\n+        try!(ui.para(\"\"));\n+        Ok(Some(ident))\n+    } else {\n+        try!(ui.warn(\n+            \"Unable to determine the type of app in your current directory\",\n+        ));\n+        try!(ui.para(\n+            \"For now, we'll generate a plan with all of the available plan options and callbacks. \\\n+            For more documentation on plan options try passing --withdocs or visit \\\n+            https://www.habitat.sh/docs/reference/plan-syntax/\",\n+        ));\n+        Ok(None)\n+    }\n+}\n+\n+fn is_project_ruby(path: &Path) -> bool {\n+    if path.join(\"Gemfile\").is_file() {\n+        return true;\n+    }\n+\n+    if let Some(parent) = path.parent() {","path":"components/hab/src/scaffolding.rs","position":116,"original_position":116,"commit_id":"f00ce0033bdbef0a50e4d6a156802d172a2b40fb","original_commit_id":"f00ce0033bdbef0a50e4d6a156802d172a2b40fb","user":{"login":"eeyun","id":12615148,"avatar_url":"https://avatars1.githubusercontent.com/u/12615148?v=4","gravatar_id":"","url":"https://api.github.com/users/eeyun","html_url":"https://github.com/eeyun","followers_url":"https://api.github.com/users/eeyun/followers","following_url":"https://api.github.com/users/eeyun/following{/other_user}","gists_url":"https://api.github.com/users/eeyun/gists{/gist_id}","starred_url":"https://api.github.com/users/eeyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eeyun/subscriptions","organizations_url":"https://api.github.com/users/eeyun/orgs","repos_url":"https://api.github.com/users/eeyun/repos","events_url":"https://api.github.com/users/eeyun/events{/privacy}","received_events_url":"https://api.github.com/users/eeyun/received_events","type":"User","site_admin":false},"body":"Yep, we only want to check the current, I think I left these in there from an alternative implementation I was thinking through. Happy to get rid of unnecessary nonsense!","created_at":"2017-07-28T22:22:39Z","updated_at":"2017-07-28T22:22:39Z","html_url":"https://github.com/habitat-sh/habitat/pull/2847#discussion_r130197965","pull_request_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847","_links":{"self":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments/130197965"},"html":{"href":"https://github.com/habitat-sh/habitat/pull/2847#discussion_r130197965"},"pull_request":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847"}}},"pull_request":{"url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847","id":133044412,"html_url":"https://github.com/habitat-sh/habitat/pull/2847","diff_url":"https://github.com/habitat-sh/habitat/pull/2847.diff","patch_url":"https://github.com/habitat-sh/habitat/pull/2847.patch","issue_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2847","number":2847,"state":"open","locked":false,"title":"Hab plan init rewrite with autodetection","user":{"login":"eeyun","id":12615148,"avatar_url":"https://avatars1.githubusercontent.com/u/12615148?v=4","gravatar_id":"","url":"https://api.github.com/users/eeyun","html_url":"https://github.com/eeyun","followers_url":"https://api.github.com/users/eeyun/followers","following_url":"https://api.github.com/users/eeyun/following{/other_user}","gists_url":"https://api.github.com/users/eeyun/gists{/gist_id}","starred_url":"https://api.github.com/users/eeyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eeyun/subscriptions","organizations_url":"https://api.github.com/users/eeyun/orgs","repos_url":"https://api.github.com/users/eeyun/repos","events_url":"https://api.github.com/users/eeyun/events{/privacy}","received_events_url":"https://api.github.com/users/eeyun/received_events","type":"User","site_admin":false},"body":"Signed-off-by: eeyun <ihenry@chef.io>\r\n\r\nThis pr is the first iteration of rewriting the `hab plan init` subcommand to start using auto detection and push new users towards leveraging the scaffolding.\r\n\r\nA reminder that this pr consists of the first two commits that move towards utilizing this autodiscovery behavior out of the box for new users.\r\n\r\n","created_at":"2017-07-28T20:18:04Z","updated_at":"2017-07-28T22:22:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bdb95325e663878884c0f3d22db79f1f520ae081","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847/commits","review_comments_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847/comments","review_comment_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments{/number}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2847/comments","statuses_url":"https://api.github.com/repos/habitat-sh/habitat/statuses/f00ce0033bdbef0a50e4d6a156802d172a2b40fb","head":{"label":"habitat-sh:eeyun/init_rewrite_clean","ref":"eeyun/init_rewrite_clean","sha":"f00ce0033bdbef0a50e4d6a156802d172a2b40fb","user":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars0.githubusercontent.com/u/18171698?v=4","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"repo":{"id":36098429,"name":"habitat","full_name":"habitat-sh/habitat","owner":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars0.githubusercontent.com/u/18171698?v=4","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/habitat-sh/habitat","description":"Modern applications with built-in automation","fork":false,"url":"https://api.github.com/repos/habitat-sh/habitat","forks_url":"https://api.github.com/repos/habitat-sh/habitat/forks","keys_url":"https://api.github.com/repos/habitat-sh/habitat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/habitat-sh/habitat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/habitat-sh/habitat/teams","hooks_url":"https://api.github.com/repos/habitat-sh/habitat/hooks","issue_events_url":"https://api.github.com/repos/habitat-sh/habitat/issues/events{/number}","events_url":"https://api.github.com/repos/habitat-sh/habitat/events","assignees_url":"https://api.github.com/repos/habitat-sh/habitat/assignees{/user}","branches_url":"https://api.github.com/repos/habitat-sh/habitat/branches{/branch}","tags_url":"https://api.github.com/repos/habitat-sh/habitat/tags","blobs_url":"https://api.github.com/repos/habitat-sh/habitat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/habitat-sh/habitat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/habitat-sh/habitat/git/refs{/sha}","trees_url":"https://api.github.com/repos/habitat-sh/habitat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/habitat-sh/habitat/statuses/{sha}","languages_url":"https://api.github.com/repos/habitat-sh/habitat/languages","stargazers_url":"https://api.github.com/repos/habitat-sh/habitat/stargazers","contributors_url":"https://api.github.com/repos/habitat-sh/habitat/contributors","subscribers_url":"https://api.github.com/repos/habitat-sh/habitat/subscribers","subscription_url":"https://api.github.com/repos/habitat-sh/habitat/subscription","commits_url":"https://api.github.com/repos/habitat-sh/habitat/commits{/sha}","git_commits_url":"https://api.github.com/repos/habitat-sh/habitat/git/commits{/sha}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/comments{/number}","issue_comment_url":"https://api.github.com/repos/habitat-sh/habitat/issues/comments{/number}","contents_url":"https://api.github.com/repos/habitat-sh/habitat/contents/{+path}","compare_url":"https://api.github.com/repos/habitat-sh/habitat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/habitat-sh/habitat/merges","archive_url":"https://api.github.com/repos/habitat-sh/habitat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/habitat-sh/habitat/downloads","issues_url":"https://api.github.com/repos/habitat-sh/habitat/issues{/number}","pulls_url":"https://api.github.com/repos/habitat-sh/habitat/pulls{/number}","milestones_url":"https://api.github.com/repos/habitat-sh/habitat/milestones{/number}","notifications_url":"https://api.github.com/repos/habitat-sh/habitat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/habitat-sh/habitat/labels{/name}","releases_url":"https://api.github.com/repos/habitat-sh/habitat/releases{/id}","deployments_url":"https://api.github.com/repos/habitat-sh/habitat/deployments","created_at":"2015-05-22T22:47:14Z","updated_at":"2017-07-28T20:39:18Z","pushed_at":"2017-07-28T22:08:43Z","git_url":"git://github.com/habitat-sh/habitat.git","ssh_url":"git@github.com:habitat-sh/habitat.git","clone_url":"https://github.com/habitat-sh/habitat.git","svn_url":"https://github.com/habitat-sh/habitat","homepage":"https://www.habitat.sh","size":52688,"stargazers_count":1149,"watchers_count":1149,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":175,"mirror_url":null,"open_issues_count":236,"forks":175,"open_issues":236,"watchers":1149,"default_branch":"master"}},"base":{"label":"habitat-sh:master","ref":"master","sha":"182ef7b4035aea078ad98018257e5190f759f18b","user":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars0.githubusercontent.com/u/18171698?v=4","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"repo":{"id":36098429,"name":"habitat","full_name":"habitat-sh/habitat","owner":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars0.githubusercontent.com/u/18171698?v=4","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/habitat-sh/habitat","description":"Modern applications with built-in automation","fork":false,"url":"https://api.github.com/repos/habitat-sh/habitat","forks_url":"https://api.github.com/repos/habitat-sh/habitat/forks","keys_url":"https://api.github.com/repos/habitat-sh/habitat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/habitat-sh/habitat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/habitat-sh/habitat/teams","hooks_url":"https://api.github.com/repos/habitat-sh/habitat/hooks","issue_events_url":"https://api.github.com/repos/habitat-sh/habitat/issues/events{/number}","events_url":"https://api.github.com/repos/habitat-sh/habitat/events","assignees_url":"https://api.github.com/repos/habitat-sh/habitat/assignees{/user}","branches_url":"https://api.github.com/repos/habitat-sh/habitat/branches{/branch}","tags_url":"https://api.github.com/repos/habitat-sh/habitat/tags","blobs_url":"https://api.github.com/repos/habitat-sh/habitat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/habitat-sh/habitat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/habitat-sh/habitat/git/refs{/sha}","trees_url":"https://api.github.com/repos/habitat-sh/habitat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/habitat-sh/habitat/statuses/{sha}","languages_url":"https://api.github.com/repos/habitat-sh/habitat/languages","stargazers_url":"https://api.github.com/repos/habitat-sh/habitat/stargazers","contributors_url":"https://api.github.com/repos/habitat-sh/habitat/contributors","subscribers_url":"https://api.github.com/repos/habitat-sh/habitat/subscribers","subscription_url":"https://api.github.com/repos/habitat-sh/habitat/subscription","commits_url":"https://api.github.com/repos/habitat-sh/habitat/commits{/sha}","git_commits_url":"https://api.github.com/repos/habitat-sh/habitat/git/commits{/sha}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/comments{/number}","issue_comment_url":"https://api.github.com/repos/habitat-sh/habitat/issues/comments{/number}","contents_url":"https://api.github.com/repos/habitat-sh/habitat/contents/{+path}","compare_url":"https://api.github.com/repos/habitat-sh/habitat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/habitat-sh/habitat/merges","archive_url":"https://api.github.com/repos/habitat-sh/habitat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/habitat-sh/habitat/downloads","issues_url":"https://api.github.com/repos/habitat-sh/habitat/issues{/number}","pulls_url":"https://api.github.com/repos/habitat-sh/habitat/pulls{/number}","milestones_url":"https://api.github.com/repos/habitat-sh/habitat/milestones{/number}","notifications_url":"https://api.github.com/repos/habitat-sh/habitat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/habitat-sh/habitat/labels{/name}","releases_url":"https://api.github.com/repos/habitat-sh/habitat/releases{/id}","deployments_url":"https://api.github.com/repos/habitat-sh/habitat/deployments","created_at":"2015-05-22T22:47:14Z","updated_at":"2017-07-28T20:39:18Z","pushed_at":"2017-07-28T22:08:43Z","git_url":"git://github.com/habitat-sh/habitat.git","ssh_url":"git@github.com:habitat-sh/habitat.git","clone_url":"https://github.com/habitat-sh/habitat.git","svn_url":"https://github.com/habitat-sh/habitat","homepage":"https://www.habitat.sh","size":52688,"stargazers_count":1149,"watchers_count":1149,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":175,"mirror_url":null,"open_issues_count":236,"forks":175,"open_issues":236,"watchers":1149,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847"},"html":{"href":"https://github.com/habitat-sh/habitat/pull/2847"},"issue":{"href":"https://api.github.com/repos/habitat-sh/habitat/issues/2847"},"comments":{"href":"https://api.github.com/repos/habitat-sh/habitat/issues/2847/comments"},"review_comments":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847/comments"},"review_comment":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2847/commits"},"statuses":{"href":"https://api.github.com/repos/habitat-sh/habitat/statuses/f00ce0033bdbef0a50e4d6a156802d172a2b40fb"}}}}
{"actor":{"display_login":"eeyun"}}