{"action":"created","comment":{"url":"https://api.github.com/repos/rundel/ghclass/pulls/comments/294358697","pull_request_review_id":250521832,"id":294358697,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI5NDM1ODY5Nw==","diff_hunk":"@@ -185,6 +191,166 @@ put_file = function(repo, path, content, message, branch = \"master\") {\n \n \n \n+#' Create file URL to pass to GitHub Commit API\n+#'\n+#' `create_file_commit_url` creates a file URL for a single file that can be passed to a `gh::gh(METHOD URL)` query. The query is limited to 100 entries.\n+#'\n+#'\n+create_file_commit_url = function(repo, gh_path){\n+\n+  stopifnot(length(repo) == 1)\n+  stopifnot(length(gh_path) == 1)\n+\n+  owner = get_repo_owner(repo)\n+  name = get_repo_name(repo)\n+  paste0(\"https://api.github.com/repos/\",\n+         owner, \"/\",\n+         name, \"/commits?path=\",\n+         gh_path,\n+         \"&page=1&per_page=100\")\n+}\n+\n+github_api_get_commit_history = function(repo, gh_path){\n+\n+  safe_gh(paste0(\"GET \", create_file_commit_url(repo, gh_path)),\n+          .token=get_github_token())\n+\n+}\n+\n+#' Check for modifications of file on GitHub\n+#'\n+#' `check_file_modification` checks whether a file on GitHub has previously been modified by a commit (not taking into account the initial commit).\n+#'\n+#' @param repo Character. Address of repository in \"owner/name\" format.\n+#' @param file Character. Name of file.\n+#' @param include_admin Logical. Should users with admin privileges be included in checking for previous file modifications.\n+#'\n+#' @return TRUE or FALSE\n+#'\n+check_file_modification = function(repo, gh_path, include_admin){\n+\n+  res = github_api_get_commit_history(repo, gh_path)\n+\n+  if(length(res$result) > 1){\n+\n+    user = unique(purrr::map_chr(res$result, c(\"author\", \"login\")))\n+\n+    if(!include_admin){\n+      user = setdiff(user, unlist(get_admins(get_repo_owner(repo))))\n+    }\n+\n+    if(!is.null(user)){\n+      purrr::walk(user,\n+                  function(user){\n+                    usethis::ui_oops(\"Adding {usethis::ui_value(gh_path)} to {usethis::ui_value(repo)} overwrites modifications by student(s): {usethis::ui_value(user)}.\")\n+                    usethis::ui_info(\"If you want to overwrite modifications, re-run with overwrite = TRUE.\")\n+                    message(\" \")\n+                  })\n+    }\n+  }\n+}\n+\n+\n+\n+\n+\n+#' Add files to a repo\n+#'\n+#' `add_file` uses the GitHub API to add/update files in an existing repo on GitHub. Note that due to time delays in caching, files that have been added very recently might not yet be displayed as existing and might accidentally be overwritten.\n+#'\n+#' @param repo Character. Address of repository in \"owner/name\" format.\n+#' @param message Character. Commit message. If not provided, a custom character string will be created, in the form of \"Added file(s): filename(s)\". If this custom message character length exceeds 50, it will be shortened to \"Added file(s)\".\n+#' @param file Character. Local file path(s) of file or files to be added.\n+#' @param branch Character. Name of branch to use, defaults to \"master\".\n+#' @param preserve_path Logical. Should the local relative path be preserved.\n+#' @param overwrite Logical. Should existing file or files with same name be overwritten, defaults to FALSE.\n+#' @param include_admin Logical. Should users with admin privileges be included in checking for previous file modifications, defaults to FALSE.\n+#'\n+#' @examples\n+#' \\dontrun{\n+#' add_file(\"rundel/ghclass\", \"Update DESCRIPTION\", \"./DESCRIPTION\")\n+#' }\n+#'\n+#' @aliases grab_repos\n+#'\n+#' @family local repo functions\n+#'\n+#' @export\n+#'\n+add_file = function(repo, file, message = NULL, branch = \"master\", preserve_path = FALSE, overwrite = FALSE, include_admin = FALSE){","path":"R/repo_files.R","position":204,"original_position":204,"commit_id":"a43f689e650fb95bd88163b7993c34e6ba0584bd","original_commit_id":"a43f689e650fb95bd88163b7993c34e6ba0584bd","user":{"login":"mine-cetinkaya-rundel","id":5965649,"node_id":"MDQ6VXNlcjU5NjU2NDk=","avatar_url":"https://avatars0.githubusercontent.com/u/5965649?v=4","gravatar_id":"","url":"https://api.github.com/users/mine-cetinkaya-rundel","html_url":"https://github.com/mine-cetinkaya-rundel","followers_url":"https://api.github.com/users/mine-cetinkaya-rundel/followers","following_url":"https://api.github.com/users/mine-cetinkaya-rundel/following{/other_user}","gists_url":"https://api.github.com/users/mine-cetinkaya-rundel/gists{/gist_id}","starred_url":"https://api.github.com/users/mine-cetinkaya-rundel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mine-cetinkaya-rundel/subscriptions","organizations_url":"https://api.github.com/users/mine-cetinkaya-rundel/orgs","repos_url":"https://api.github.com/users/mine-cetinkaya-rundel/repos","events_url":"https://api.github.com/users/mine-cetinkaya-rundel/events{/privacy}","received_events_url":"https://api.github.com/users/mine-cetinkaya-rundel/received_events","type":"User","site_admin":false},"body":"So I was able to break things when I ran the following\r\n\r\n```r\r\nadd_file(\"ghclass-test/hw99-mine-private\", file = \"README.md\", overwrite = TRUE)\r\n```\r\n\r\nIt works, but it gives me an error, tracing back to `utils.R`. Give it a try and see what you get.","created_at":"2019-06-17T15:32:54Z","updated_at":"2019-06-17T15:39:36Z","html_url":"https://github.com/rundel/ghclass/pull/37#discussion_r294358697","pull_request_url":"https://api.github.com/repos/rundel/ghclass/pulls/37","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/rundel/ghclass/pulls/comments/294358697"},"html":{"href":"https://github.com/rundel/ghclass/pull/37#discussion_r294358697"},"pull_request":{"href":"https://api.github.com/repos/rundel/ghclass/pulls/37"}}},"pull_request":{"url":"https://api.github.com/repos/rundel/ghclass/pulls/37","id":288636280,"node_id":"MDExOlB1bGxSZXF1ZXN0Mjg4NjM2Mjgw","html_url":"https://github.com/rundel/ghclass/pull/37","diff_url":"https://github.com/rundel/ghclass/pull/37.diff","patch_url":"https://github.com/rundel/ghclass/pull/37.patch","issue_url":"https://api.github.com/repos/rundel/ghclass/issues/37","number":37,"state":"open","locked":false,"title":"`add_file` function with modification check","user":{"login":"thereseanders","id":26805373,"node_id":"MDQ6VXNlcjI2ODA1Mzcz","avatar_url":"https://avatars1.githubusercontent.com/u/26805373?v=4","gravatar_id":"","url":"https://api.github.com/users/thereseanders","html_url":"https://github.com/thereseanders","followers_url":"https://api.github.com/users/thereseanders/followers","following_url":"https://api.github.com/users/thereseanders/following{/other_user}","gists_url":"https://api.github.com/users/thereseanders/gists{/gist_id}","starred_url":"https://api.github.com/users/thereseanders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thereseanders/subscriptions","organizations_url":"https://api.github.com/users/thereseanders/orgs","repos_url":"https://api.github.com/users/thereseanders/repos","events_url":"https://api.github.com/users/thereseanders/events{/privacy}","received_events_url":"https://api.github.com/users/thereseanders/received_events","type":"User","site_admin":false},"body":"This commit \r\n- fixes broken `get_file` function\r\n- adds a modification check to `add_file`\r\n- minor fixes to other functions\r\n- moves deprecated functions to bottom of file\r\n- adds function `check_file_modification` \r\n- adds function `github_api_get_commit_history`\r\n- adds function `create_file_commit_url`","created_at":"2019-06-16T16:33:24Z","updated_at":"2019-06-17T15:39:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1b0477d54bfbc1dced4a81fc50517aab58946f2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rundel/ghclass/pulls/37/commits","review_comments_url":"https://api.github.com/repos/rundel/ghclass/pulls/37/comments","review_comment_url":"https://api.github.com/repos/rundel/ghclass/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rundel/ghclass/issues/37/comments","statuses_url":"https://api.github.com/repos/rundel/ghclass/statuses/a43f689e650fb95bd88163b7993c34e6ba0584bd","head":{"label":"thereseanders:add_file_190616","ref":"add_file_190616","sha":"a43f689e650fb95bd88163b7993c34e6ba0584bd","user":{"login":"thereseanders","id":26805373,"node_id":"MDQ6VXNlcjI2ODA1Mzcz","avatar_url":"https://avatars1.githubusercontent.com/u/26805373?v=4","gravatar_id":"","url":"https://api.github.com/users/thereseanders","html_url":"https://github.com/thereseanders","followers_url":"https://api.github.com/users/thereseanders/followers","following_url":"https://api.github.com/users/thereseanders/following{/other_user}","gists_url":"https://api.github.com/users/thereseanders/gists{/gist_id}","starred_url":"https://api.github.com/users/thereseanders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thereseanders/subscriptions","organizations_url":"https://api.github.com/users/thereseanders/orgs","repos_url":"https://api.github.com/users/thereseanders/repos","events_url":"https://api.github.com/users/thereseanders/events{/privacy}","received_events_url":"https://api.github.com/users/thereseanders/received_events","type":"User","site_admin":false},"repo":{"id":189099512,"node_id":"MDEwOlJlcG9zaXRvcnkxODkwOTk1MTI=","name":"ghclass","full_name":"thereseanders/ghclass","private":false,"owner":{"login":"thereseanders","id":26805373,"node_id":"MDQ6VXNlcjI2ODA1Mzcz","avatar_url":"https://avatars1.githubusercontent.com/u/26805373?v=4","gravatar_id":"","url":"https://api.github.com/users/thereseanders","html_url":"https://github.com/thereseanders","followers_url":"https://api.github.com/users/thereseanders/followers","following_url":"https://api.github.com/users/thereseanders/following{/other_user}","gists_url":"https://api.github.com/users/thereseanders/gists{/gist_id}","starred_url":"https://api.github.com/users/thereseanders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thereseanders/subscriptions","organizations_url":"https://api.github.com/users/thereseanders/orgs","repos_url":"https://api.github.com/users/thereseanders/repos","events_url":"https://api.github.com/users/thereseanders/events{/privacy}","received_events_url":"https://api.github.com/users/thereseanders/received_events","type":"User","site_admin":false},"html_url":"https://github.com/thereseanders/ghclass","description":"Tools for managing classroom organizations","fork":true,"url":"https://api.github.com/repos/thereseanders/ghclass","forks_url":"https://api.github.com/repos/thereseanders/ghclass/forks","keys_url":"https://api.github.com/repos/thereseanders/ghclass/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thereseanders/ghclass/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thereseanders/ghclass/teams","hooks_url":"https://api.github.com/repos/thereseanders/ghclass/hooks","issue_events_url":"https://api.github.com/repos/thereseanders/ghclass/issues/events{/number}","events_url":"https://api.github.com/repos/thereseanders/ghclass/events","assignees_url":"https://api.github.com/repos/thereseanders/ghclass/assignees{/user}","branches_url":"https://api.github.com/repos/thereseanders/ghclass/branches{/branch}","tags_url":"https://api.github.com/repos/thereseanders/ghclass/tags","blobs_url":"https://api.github.com/repos/thereseanders/ghclass/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thereseanders/ghclass/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thereseanders/ghclass/git/refs{/sha}","trees_url":"https://api.github.com/repos/thereseanders/ghclass/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thereseanders/ghclass/statuses/{sha}","languages_url":"https://api.github.com/repos/thereseanders/ghclass/languages","stargazers_url":"https://api.github.com/repos/thereseanders/ghclass/stargazers","contributors_url":"https://api.github.com/repos/thereseanders/ghclass/contributors","subscribers_url":"https://api.github.com/repos/thereseanders/ghclass/subscribers","subscription_url":"https://api.github.com/repos/thereseanders/ghclass/subscription","commits_url":"https://api.github.com/repos/thereseanders/ghclass/commits{/sha}","git_commits_url":"https://api.github.com/repos/thereseanders/ghclass/git/commits{/sha}","comments_url":"https://api.github.com/repos/thereseanders/ghclass/comments{/number}","issue_comment_url":"https://api.github.com/repos/thereseanders/ghclass/issues/comments{/number}","contents_url":"https://api.github.com/repos/thereseanders/ghclass/contents/{+path}","compare_url":"https://api.github.com/repos/thereseanders/ghclass/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thereseanders/ghclass/merges","archive_url":"https://api.github.com/repos/thereseanders/ghclass/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thereseanders/ghclass/downloads","issues_url":"https://api.github.com/repos/thereseanders/ghclass/issues{/number}","pulls_url":"https://api.github.com/repos/thereseanders/ghclass/pulls{/number}","milestones_url":"https://api.github.com/repos/thereseanders/ghclass/milestones{/number}","notifications_url":"https://api.github.com/repos/thereseanders/ghclass/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thereseanders/ghclass/labels{/name}","releases_url":"https://api.github.com/repos/thereseanders/ghclass/releases{/id}","deployments_url":"https://api.github.com/repos/thereseanders/ghclass/deployments","created_at":"2019-05-28T20:35:38Z","updated_at":"2019-06-16T14:52:51Z","pushed_at":"2019-06-17T15:28:50Z","git_url":"git://github.com/thereseanders/ghclass.git","ssh_url":"git@github.com:thereseanders/ghclass.git","clone_url":"https://github.com/thereseanders/ghclass.git","svn_url":"https://github.com/thereseanders/ghclass","homepage":"https://rundel.github.io/ghclass/","size":415,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rundel:master","ref":"master","sha":"bd0004310f5b92da92112bfc2214d099fde1ac5d","user":{"login":"rundel","id":273926,"node_id":"MDQ6VXNlcjI3MzkyNg==","avatar_url":"https://avatars0.githubusercontent.com/u/273926?v=4","gravatar_id":"","url":"https://api.github.com/users/rundel","html_url":"https://github.com/rundel","followers_url":"https://api.github.com/users/rundel/followers","following_url":"https://api.github.com/users/rundel/following{/other_user}","gists_url":"https://api.github.com/users/rundel/gists{/gist_id}","starred_url":"https://api.github.com/users/rundel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rundel/subscriptions","organizations_url":"https://api.github.com/users/rundel/orgs","repos_url":"https://api.github.com/users/rundel/repos","events_url":"https://api.github.com/users/rundel/events{/privacy}","received_events_url":"https://api.github.com/users/rundel/received_events","type":"User","site_admin":false},"repo":{"id":67464178,"node_id":"MDEwOlJlcG9zaXRvcnk2NzQ2NDE3OA==","name":"ghclass","full_name":"rundel/ghclass","private":false,"owner":{"login":"rundel","id":273926,"node_id":"MDQ6VXNlcjI3MzkyNg==","avatar_url":"https://avatars0.githubusercontent.com/u/273926?v=4","gravatar_id":"","url":"https://api.github.com/users/rundel","html_url":"https://github.com/rundel","followers_url":"https://api.github.com/users/rundel/followers","following_url":"https://api.github.com/users/rundel/following{/other_user}","gists_url":"https://api.github.com/users/rundel/gists{/gist_id}","starred_url":"https://api.github.com/users/rundel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rundel/subscriptions","organizations_url":"https://api.github.com/users/rundel/orgs","repos_url":"https://api.github.com/users/rundel/repos","events_url":"https://api.github.com/users/rundel/events{/privacy}","received_events_url":"https://api.github.com/users/rundel/received_events","type":"User","site_admin":false},"html_url":"https://github.com/rundel/ghclass","description":"Tools for managing classroom organizations","fork":false,"url":"https://api.github.com/repos/rundel/ghclass","forks_url":"https://api.github.com/repos/rundel/ghclass/forks","keys_url":"https://api.github.com/repos/rundel/ghclass/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rundel/ghclass/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rundel/ghclass/teams","hooks_url":"https://api.github.com/repos/rundel/ghclass/hooks","issue_events_url":"https://api.github.com/repos/rundel/ghclass/issues/events{/number}","events_url":"https://api.github.com/repos/rundel/ghclass/events","assignees_url":"https://api.github.com/repos/rundel/ghclass/assignees{/user}","branches_url":"https://api.github.com/repos/rundel/ghclass/branches{/branch}","tags_url":"https://api.github.com/repos/rundel/ghclass/tags","blobs_url":"https://api.github.com/repos/rundel/ghclass/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rundel/ghclass/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rundel/ghclass/git/refs{/sha}","trees_url":"https://api.github.com/repos/rundel/ghclass/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rundel/ghclass/statuses/{sha}","languages_url":"https://api.github.com/repos/rundel/ghclass/languages","stargazers_url":"https://api.github.com/repos/rundel/ghclass/stargazers","contributors_url":"https://api.github.com/repos/rundel/ghclass/contributors","subscribers_url":"https://api.github.com/repos/rundel/ghclass/subscribers","subscription_url":"https://api.github.com/repos/rundel/ghclass/subscription","commits_url":"https://api.github.com/repos/rundel/ghclass/commits{/sha}","git_commits_url":"https://api.github.com/repos/rundel/ghclass/git/commits{/sha}","comments_url":"https://api.github.com/repos/rundel/ghclass/comments{/number}","issue_comment_url":"https://api.github.com/repos/rundel/ghclass/issues/comments{/number}","contents_url":"https://api.github.com/repos/rundel/ghclass/contents/{+path}","compare_url":"https://api.github.com/repos/rundel/ghclass/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rundel/ghclass/merges","archive_url":"https://api.github.com/repos/rundel/ghclass/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rundel/ghclass/downloads","issues_url":"https://api.github.com/repos/rundel/ghclass/issues{/number}","pulls_url":"https://api.github.com/repos/rundel/ghclass/pulls{/number}","milestones_url":"https://api.github.com/repos/rundel/ghclass/milestones{/number}","notifications_url":"https://api.github.com/repos/rundel/ghclass/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rundel/ghclass/labels{/name}","releases_url":"https://api.github.com/repos/rundel/ghclass/releases{/id}","deployments_url":"https://api.github.com/repos/rundel/ghclass/deployments","created_at":"2016-09-06T01:58:21Z","updated_at":"2019-06-13T12:50:15Z","pushed_at":"2019-06-17T15:28:51Z","git_url":"git://github.com/rundel/ghclass.git","ssh_url":"git@github.com:rundel/ghclass.git","clone_url":"https://github.com/rundel/ghclass.git","svn_url":"https://github.com/rundel/ghclass","homepage":"https://rundel.github.io/ghclass/","size":371,"stargazers_count":47,"watchers_count":47,"language":"R","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":11,"license":null,"forks":7,"open_issues":11,"watchers":47,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rundel/ghclass/pulls/37"},"html":{"href":"https://github.com/rundel/ghclass/pull/37"},"issue":{"href":"https://api.github.com/repos/rundel/ghclass/issues/37"},"comments":{"href":"https://api.github.com/repos/rundel/ghclass/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/rundel/ghclass/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/rundel/ghclass/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rundel/ghclass/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/rundel/ghclass/statuses/a43f689e650fb95bd88163b7993c34e6ba0584bd"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mine-cetinkaya-rundel"}}