Skip to content

Commit

Permalink
release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco committed Jan 1, 2020
1 parent b479905 commit 25ec0f9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

## [1.1.0] - 2020-01-01

### :zap: Added

- Support for BSD 2-clause "Simplified" licenses
Expand All @@ -14,4 +16,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [1.0.0] - 2020-01-01

Initial version
### :zap: Added

- Support for Apache 2.0 licenses
44 changes: 35 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,17 @@ class GitHub {
class License {
constructor() {
// Regular expressions finding the copyright year(s) in Apache 2.0 license files
this.copyrightYear = /(Copyright )(\d{4})( \w+)/gm;
this.copyrightYearRange = /(Copyright )(\d{4})-(\d{4})( \w+)/gm;
this.apacheCopyrightYear = /(Copyright )(\d{4})( \w+)/gm;
this.apacheCopyrightYearRange = /(Copyright )(\d{4})-(\d{4})( \w+)/gm;

// Regular expressions finding the copyright year(s) in BSD 2-clause "Simplified" and
// BSD 3-clause "New" or "Revised" license files
this.bsdCopyrightYear = /(Copyright \(c\) )(\d{4})(, \w+)/gm;
this.bsdCopyrightYearRange = /(Copyright \(c\) )(\d{4})-(\d{4})(, \w+)/gm;

// Regular expressions finding the copyright year(s) in MIT license files
this.mitCopyrightYear = /(Copyright \(c\) )(\d{4})( \w+)/gm;
this.mitCopyrightYearRange = /(Copyright \(c\) )(\d{4})-(\d{4})( \w+)/gm;
}

update(license) {
Expand All @@ -476,15 +485,32 @@ class License {
}

updateToYear(license, year) {
if (this.copyrightYear.test(license)) {
license = license.replace(this.copyrightYear, `$1$2-${year}$3`);
} else if (this.copyrightYearRange.test(license)) {
license = license.replace(this.copyrightYearRange, `$1$2-${year}$4`);
} else {
throw new Error("Specified license is not supported");
// Apache 2.0
if (this.apacheCopyrightYear.test(license)) {
return license.replace(this.apacheCopyrightYear, `$1$2-${year}$3`);
}
if (this.apacheCopyrightYearRange.test(license)) {
return license.replace(this.apacheCopyrightYearRange, `$1$2-${year}$4`);
}

// BSD 2-clause "Simplified"
// BSD 3-clause "New" or "Revised"
if (this.bsdCopyrightYear.test(license)) {
return license.replace(this.bsdCopyrightYear, `$1$2-${year}$3`);
}
if (this.bsdCopyrightYearRange.test(license)) {
return license.replace(this.bsdCopyrightYearRange, `$1$2-${year}$4`);
}

// MIT
if (this.mitCopyrightYear.test(license)) {
return license.replace(this.mitCopyrightYear, `$1$2-${year}$3`);
}
if (this.mitCopyrightYearRange.test(license)) {
return license.replace(this.mitCopyrightYearRange, `$1$2-${year}$4`);
}

return license;
throw new Error("Specified license is not supported");
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "action-update-license-year",
"version": "1.0.0",
"version": "1.1.0",
"description": "GitHub Action that in a pull request updates the copyright year(s) in your license file.",
"keywords": [
"github",
Expand Down

0 comments on commit 25ec0f9

Please sign in to comment.