Skip to content

Commit

Permalink
Merge pull request #173 from simplybusiness/generalise
Browse files Browse the repository at this point in the history
Generalise
  • Loading branch information
peaky76 authored Jan 12, 2024
2 parents 9621398 + 4120196 commit 63f31d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

“Dobby is free.”

A Github action which provides chat-ops functionality. You can comment on Pull request to perform various operations.
Currently it supports bumping version for a gem.
A Github action which provides chat-ops functionality. You can comment on a pull request to perform various operations.
Currently it supports bumping version files in Ruby, Python and Javascript. The version file (see below) must specify the version
as a key-value pair separated by either ":" or "=", e.g. `VERSION: '1.2.3'` or `version = 1.2.3`

## Bump version

Expand All @@ -14,8 +15,8 @@ Dobby requires a Github App to be installed either on an individual repository o
- Set GitHub App name.
- Set Homepage URL to your github repository.
- Uncheck Active under Webhook. You do not need to enter a Webhook URL.
- Under Repository permissions: Contents select Access: Read & write.
- Under Repository permissions: Pull requests select Access: Read & write.
- Under Permissions & Events > Repository permissions > Contents select Access: Read & write.
- Under Permissions & Events > Repository permissions > Pull requests select Access: Read & write.

2. Create a Private key from the App settings page and store it securely.

Expand Down
4 changes: 2 additions & 2 deletions lib/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Command
def initialize(config)
@config = config
comment = config.payload['comment']['body'].strip.downcase
error_msg = "Comment must be start with #{COMMAND_PREFIX}"
puts "::error title=Arguement Error::#{error_msg}"
error_msg = "Comment must start with #{COMMAND_PREFIX}"
puts "::error title=Argument Error::#{error_msg}"
raise ArgumentError, error_msg unless comment.start_with?(COMMAND_PREFIX)

cmd = comment.delete_prefix(COMMAND_PREFIX)
Expand Down
11 changes: 6 additions & 5 deletions lib/utils/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
require_relative 'commit'

class Bump
SEMVER_VERSION =
/["'](0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?["']/ # rubocop:disable Layout/LineLength
GEMSPEC_VERSION = Regexp.new(/\.version\s*=\s*/.to_s + SEMVER_VERSION.to_s).freeze
SEMVER = /["']*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?["']*/ # rubocop:disable Layout/LineLength
SEPARATOR = /\s*[:=]\s*/
VERSION_KEY = /(^|\.|\s)version/
VERSION_SETTING = Regexp.new(VERSION_KEY.source + SEPARATOR.source + SEMVER.source, Regexp::IGNORECASE).freeze

def initialize(config, level)
@config = config
Expand Down Expand Up @@ -56,8 +57,8 @@ def assign_pr_attributes!(pr_number)
end

def fetch_version(content)
version = content.content.match(GEMSPEC_VERSION) || content.content.match(SEMVER_VERSION)
Semantic::Version.new(version[0].split('=').last.gsub(/\s/, '').gsub(/'|"/, ''))
version = content.content.match(VERSION_SETTING)
Semantic::Version.new(version[0].split(SEPARATOR).last.gsub(/\s/, '').gsub(/'|"/, ''))
end

def bump_version(version, level)
Expand Down

0 comments on commit 63f31d6

Please sign in to comment.