Use first SHA for last tag
Rather than having the last tag be an empty husk, generate a full changelog link using the first sha from the repository. Signed-off-by: Tom Duffield <tom@chef.io>
This commit is contained in:
		
							parent
							
								
									f57b4c283d
								
							
						
					
					
						commit
						174baec266
					
				@ -57,14 +57,23 @@ module GitHubChangelogGenerator
 | 
			
		||||
    # @param [Array] pull_requests List or PR's in new section
 | 
			
		||||
    # @param [Array] issues List of issues in new section
 | 
			
		||||
    # @param [String] newer_tag Name of the newer tag. Could be nil for `Unreleased` section
 | 
			
		||||
    # @param [String] older_tag_name Older tag, used for the links. Could be nil for last tag.
 | 
			
		||||
    # @param [String] older_tag Older tag, used for the links. Could be nil for last tag.
 | 
			
		||||
    # @return [String] Ready and parsed section
 | 
			
		||||
    def create_log_for_tag(pull_requests, issues, newer_tag, older_tag_name = nil)
 | 
			
		||||
    def create_log_for_tag(pull_requests, issues, newer_tag, older_tag = nil)
 | 
			
		||||
      newer_tag_link, newer_tag_name, newer_tag_time = detect_link_tag_time(newer_tag)
 | 
			
		||||
 | 
			
		||||
      github_site = options[:github_site] || "https://github.com"
 | 
			
		||||
      project_url = "#{github_site}/#{options[:user]}/#{options[:project]}"
 | 
			
		||||
 | 
			
		||||
      # If the older tag is nil, go back in time from the latest tag and find
 | 
			
		||||
      # the SHA for the first commit.
 | 
			
		||||
      older_tag_name =
 | 
			
		||||
        if older_tag.nil?
 | 
			
		||||
          @fetcher.commits_before(newer_tag_time).last["sha"]
 | 
			
		||||
        else
 | 
			
		||||
          older_tag["name"]
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
      log = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
 | 
			
		||||
 | 
			
		||||
      if options[:issues]
 | 
			
		||||
 | 
			
		||||
@ -83,14 +83,12 @@ module GitHubChangelogGenerator
 | 
			
		||||
    def generate_log_between_tags(older_tag, newer_tag)
 | 
			
		||||
      filtered_issues, filtered_pull_requests = filter_issues_for_tags(newer_tag, older_tag)
 | 
			
		||||
 | 
			
		||||
      older_tag_name = older_tag.nil? ? detect_since_tag : older_tag["name"]
 | 
			
		||||
 | 
			
		||||
      if newer_tag.nil? && filtered_issues.empty? && filtered_pull_requests.empty?
 | 
			
		||||
        # do not generate empty unreleased section
 | 
			
		||||
        return ""
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      create_log_for_tag(filtered_pull_requests, filtered_issues, newer_tag, older_tag_name)
 | 
			
		||||
      create_log_for_tag(filtered_pull_requests, filtered_issues, newer_tag, older_tag)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Apply all filters to issues and pull requests
 | 
			
		||||
 | 
			
		||||
@ -236,6 +236,17 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Fetch all commits before certain point
 | 
			
		||||
    #
 | 
			
		||||
    # @return [String]
 | 
			
		||||
    def commits_before(start_time)
 | 
			
		||||
      commits = []
 | 
			
		||||
      iterate_pages(@client, "commits_before", start_time.to_datetime.to_s) do |new_commits|
 | 
			
		||||
        commits.concat(new_commits)
 | 
			
		||||
      end
 | 
			
		||||
      commits
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
    def stringify_keys_deep(indata)
 | 
			
		||||
 | 
			
		||||
@ -526,4 +526,18 @@ describe GitHubChangelogGenerator::OctoFetcher do
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "#commits_before" do
 | 
			
		||||
    context "when API is valid", :vcr do
 | 
			
		||||
      let(:start_time) { Time.parse("Wed Mar 4 18:47:17 2015 +0200") }
 | 
			
		||||
 | 
			
		||||
      subject do
 | 
			
		||||
        fetcher.commits_before(start_time)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it "returns commits" do
 | 
			
		||||
        expect(subject.last["sha"]).to eq("4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d")
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user