jekyll-github-pages-gem 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +31 -24
- data/README.md +4 -1
- data/Rakefile +5 -0
- data/jekyll_github_pages.gemspec +5 -1
- data/lib/factories/base_factory.rb +40 -0
- data/lib/factories/page_factory.rb +67 -0
- data/lib/factories/post_factory.rb +55 -1
- data/lib/jekyll_github_pages.rb +7 -5
- data/lib/models/page.rb +13 -0
- data/lib/services/{post_services/base_post_service.rb → base_editing_service.rb} +2 -2
- data/lib/services/github_service.rb +69 -122
- data/lib/services/kramdown_service.rb +1 -80
- data/lib/services/page_service.rb +85 -0
- data/lib/services/post_service.rb +184 -0
- metadata +58 -8
- data/lib/services/post_services/post_creation_service.rb +0 -55
- data/lib/services/post_services/post_editing_service.rb +0 -46
- data/lib/services/post_services/post_pull_request_editing_service.rb +0 -33
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './base_post_service'
|
4
|
-
require_relative '../github_service'
|
5
|
-
|
6
|
-
module Services
|
7
|
-
##
|
8
|
-
# This class is responsible for creating posts on a Jekyll website
|
9
|
-
class PostCreationService < BasePostService
|
10
|
-
def initialize(repo_name, access_token)
|
11
|
-
super(repo_name, access_token)
|
12
|
-
end
|
13
|
-
|
14
|
-
##
|
15
|
-
# This method submits a new post to GitHub by checking out a new branch for the post,
|
16
|
-
# if the branch already doesn't exist. Commiting and pushing the markdown and any photos
|
17
|
-
# attached to the post to the branch. And then finally opening a pull request into master
|
18
|
-
# for the new post.
|
19
|
-
#
|
20
|
-
# Params
|
21
|
-
# +oauth_token+::a user's oauth access token
|
22
|
-
# +post_markdown+:: the markdown contents of a post
|
23
|
-
# +pull_request_body+::an optional pull request body for the post, it will be blank if nothing is provided
|
24
|
-
# +reviewers+:: an optional list of reviewers for the post PR
|
25
|
-
def create_post(post_markdown, post_title, pull_request_body = '', reviewers = [])
|
26
|
-
# This ref_name variable represents the branch name
|
27
|
-
# for creating a post. At the end we strip out all of the whitespace in
|
28
|
-
# the post_title to create a valid branch name
|
29
|
-
branch_name = "createPost#{post_title.gsub(/\s+/, '')}"
|
30
|
-
ref_name = "heads/#{branch_name}"
|
31
|
-
|
32
|
-
master_head_sha = @github_service.get_master_head_sha
|
33
|
-
sha_base_tree = @github_service.get_base_tree_for_branch(master_head_sha)
|
34
|
-
|
35
|
-
@github_service.create_ref_if_necessary(ref_name, master_head_sha)
|
36
|
-
|
37
|
-
new_post_path = create_new_filepath_for_post(post_title)
|
38
|
-
new_tree_sha = create_new_tree(post_markdown, post_title, new_post_path, sha_base_tree)
|
39
|
-
|
40
|
-
@github_service.commit_and_push_to_repo("Created post #{post_title}",
|
41
|
-
new_tree_sha, master_head_sha, ref_name)
|
42
|
-
@github_service.create_pull_request(branch_name, 'master', "Created Post #{post_title}",
|
43
|
-
pull_request_body,
|
44
|
-
reviewers)
|
45
|
-
|
46
|
-
PostImageManager.instance.clear
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def create_new_filepath_for_post(post_title)
|
52
|
-
"_posts/#{DateTime.now.strftime('%Y-%m-%d')}-#{post_title.gsub(/\s+/, '')}.md"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './base_post_service'
|
4
|
-
require_relative '../github_service'
|
5
|
-
|
6
|
-
module Services
|
7
|
-
##
|
8
|
-
# This class is responsible for editing posts on a Jekyll website
|
9
|
-
class PostEditingService < BasePostService
|
10
|
-
def initialize(repo_name, access_token)
|
11
|
-
super(repo_name, access_token)
|
12
|
-
end
|
13
|
-
|
14
|
-
##
|
15
|
-
# This method submits changes to an existing post to GitHub by checking out a new branch for the post,
|
16
|
-
# if the branch already doesn't exist. Commiting and pushing the markdown changes and any added photos
|
17
|
-
# for the existing post to the branch. And the finally opening a pull request into master for the new post.
|
18
|
-
#
|
19
|
-
# Params
|
20
|
-
# +post_markdown+::the modified markdown to submit
|
21
|
-
# +post_title+::the title for the existing post
|
22
|
-
# +existing_post_file_path+::the file path to the existing post on GitHub
|
23
|
-
# +pull_request_body+::an optional pull request body for the post, it will be blank if nothing is provided
|
24
|
-
# +reviewers+:: an optional list of reviewers for the post PR
|
25
|
-
def edit_post(post_markdown, post_title, existing_post_file_path, pull_request_body = '', reviewers = [])
|
26
|
-
# This ref_name variable represents the branch name
|
27
|
-
# for editing a post. At the end we strip out all of the whitespace in
|
28
|
-
# the post_title to create a valid branch name
|
29
|
-
branch_name = "editPost#{post_title.gsub(/\s+/, '')}"
|
30
|
-
ref_name = "heads/#{branch_name}"
|
31
|
-
|
32
|
-
master_head_sha = @github_service.get_master_head_sha
|
33
|
-
sha_base_tree = @github_service.get_base_tree_for_branch(master_head_sha)
|
34
|
-
|
35
|
-
@github_service.create_ref_if_necessary(ref_name, master_head_sha)
|
36
|
-
new_tree_sha = create_new_tree(post_markdown, post_title, existing_post_file_path, sha_base_tree)
|
37
|
-
|
38
|
-
@github_service.commit_and_push_to_repo("Edited post #{post_title}", new_tree_sha, master_head_sha, ref_name)
|
39
|
-
@github_service.create_pull_request(branch_name, 'master', "Edited Post #{post_title}",
|
40
|
-
pull_request_body,
|
41
|
-
reviewers)
|
42
|
-
|
43
|
-
PostImageManager.instance.clear
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './base_post_service'
|
4
|
-
require_relative '../github_service'
|
5
|
-
|
6
|
-
module Services
|
7
|
-
##
|
8
|
-
# This class is responsible for editing posts that are in PR on a Jekyll website
|
9
|
-
class PostPullRequestEditingService < BasePostService
|
10
|
-
def initialize(repo_name, access_token)
|
11
|
-
super(repo_name, access_token)
|
12
|
-
end
|
13
|
-
|
14
|
-
##
|
15
|
-
# This method submits changes to a post that is already in PR, commiting and pushing the markdown changes
|
16
|
-
# and any added photos to the branch. Since the post is in PR these changes will be a PR updated to the given branch
|
17
|
-
#
|
18
|
-
# Params:
|
19
|
-
# +post_markdown+::the modified markdown to submit
|
20
|
-
# +post_title+::the title for the existing post
|
21
|
-
# +existing_post_file_path+::the file path to the existing post on GitHub
|
22
|
-
# +ref+::the ref to update
|
23
|
-
def edit_post_in_pr(post_markdown, post_title, existing_post_file_path, ref)
|
24
|
-
ref_name = @github_service.get_ref_name_by_sha(ref)
|
25
|
-
sha_base_tree = @github_service.get_base_tree_for_branch(ref)
|
26
|
-
|
27
|
-
new_tree_sha = create_new_tree(post_markdown, post_title, existing_post_file_path, sha_base_tree)
|
28
|
-
@github_service.commit_and_push_to_repo("Edited post #{post_title}", new_tree_sha, ref, ref_name)
|
29
|
-
|
30
|
-
PostImageManager.instance.clear
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|