Class: GitlabReleaseNotes::Client
- Inherits:
-
Object
- Object
- GitlabReleaseNotes::Client
- Defined in:
- lib/gitlab_release_notes.rb
Constant Summary collapse
- JIRA_URL =
ENV['JIRA_URL']
- JIRA_IDS_REGEX =
ENV['JIRA_IDS_REGEX'] || '(\[([A-Z]{1,}-[0-9]{1,})\])(.*)'
- TIME_ZONE =
ENV['TZ'] || 'Africa/Cairo'
- ELIGABLE_COMMITS_REGEX =
ENV['ELIGABLE_COMMITS_REGEX'] || '(\[[A-Z]{1,}-[0-9]{1,}\]((?!Merge.*branch).)*$)'
- APP_VERSIONS_REGEX =
ENV['APP_VERSIONS_REGEX'] || 'v[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}'
- RELEASE_NOTES_HEADER =
ENV['RELEASE_NOTES_HEADER'] || '##### Release Notes'
Instance Method Summary collapse
- #current_time ⇒ Object
- #log_filter(logs) ⇒ Object
- #prepare_release_notes(repository_path) ⇒ Object
- #publish_release_notes(repository_id, release_tag, repository_path) ⇒ Object
- #tags_lister(repository) ⇒ Object
Instance Method Details
#current_time ⇒ Object
38 39 40 41 |
# File 'lib/gitlab_release_notes.rb', line 38 def current_time tz = TZInfo::Timezone.get(TIME_ZONE.to_s) tz.now end |
#log_filter(logs) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gitlab_release_notes.rb', line 18 def log_filter(logs) app_changelog = [] logs.each do |l| if l..match(/#{ELIGABLE_COMMITS_REGEX}/) app_changelog.append(l..gsub(/#{JIRA_IDS_REGEX}/, "\\1(#{JIRA_URL}/browse/\\2)\\3<br>")) end end app_changelog end |
#prepare_release_notes(repository_path) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gitlab_release_notes.rb', line 43 def prepare_release_notes(repository_path) repo = Git.open(repository_path) release_notes = [] app_versions = (repo) if app_versions.length == 1 release_notes = log_filter(repo.log) else eligable_versions = app_versions.last(2) release_notes = log_filter(repo.log.between(eligable_versions[0], eligable_versions[1])) end "#{RELEASE_NOTES_HEADER} (#{current_time})<br><hr> " + release_notes.uniq.join('') end |
#publish_release_notes(repository_id, release_tag, repository_path) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gitlab_release_notes.rb', line 56 def publish_release_notes(repository_id, release_tag, repository_path) release_notes = prepare_release_notes(repository_path) begin Gitlab.create_release(repository_id, release_tag, release_notes) "[#{release_tag}] Release notes have been created" rescue Gitlab::Error::Conflict Gitlab.update_release(repository_id, release_tag, release_notes) "[#{release_tag}] Release notes have been updated" end end |
#tags_lister(repository) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/gitlab_release_notes.rb', line 29 def (repository) app_versions = [] repository..each do |t| app_versions.append(t.name) \ if t.name.match(/#{APP_VERSIONS_REGEX}/) end app_versions end |