Skip to content

Commit

Permalink
Merge pull request #233 from viqueen/issue/sonar-1-fixes
Browse files Browse the repository at this point in the history
Issue/sonar 1 fixes
  • Loading branch information
viqueen authored Sep 17, 2024
2 parents 7d6ac4c + 2899c47 commit a020ceb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
10 changes: 4 additions & 6 deletions src/bin/git-stale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import { listRecentBranches } from '../lib/list-recent-branches';
import { selectAndDeleteBranches } from '../lib/select-and-delete-branches';

const mainBranches =
/^\d{4}-\d{2}-\d{2} (main|master|production|demo|website|development)$/;

const excludeOperationalBranches = async (branches: string[]) => {
return branches.filter(
(branch) =>
!branch.match(
/^\d{4}-\d{2}-\d{2} (main|master|production|demo|website|development)$/
)
);
return branches.filter((branch) => !mainBranches.exec(branch));
};

listRecentBranches()
Expand Down
16 changes: 11 additions & 5 deletions src/bin/git-sync-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
import { getConfiguration, WithProgram, withProgram } from '../lib';
import { githubItemStream } from '../streams';

const getStreamUrl = ({ user, org }: { user?: string; org?: string }) => {
if (user) {
return `/users/${user}/repos`;
}
if (org) {
return `/orgs/${org}/repos`;
}
return `/user/repos?affiliation=owner`;
};

const githubSync: WithProgram = (
{ githubUsername, githubPersonalToken, registry },
program
Expand All @@ -30,11 +40,7 @@ const githubSync: WithProgram = (
.description('sync workspace with github')
.action(async (opts) => {
const { workspace, user, org, archived, forked } = opts;
const streamUrl = user
? `/users/${user}/repos`
: org
? `/orgs/${org}/repos`
: `/user/repos?affiliation=owner`;
const streamUrl = getStreamUrl({ user, org });
await githubItemStream({
githubUsername,
githubPersonalToken,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/git-workspace-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
withProgram,
WithProgram
} from '../lib';
import { syncItemTask } from '../tasks/sync-item-task';
import { syncItemTask } from '../tasks';

const syncRepos: WithProgram = ({ registry, workspacesRoot }, program) => {
program.description('sync workspace repos').action(async (opts) => {
Expand Down
11 changes: 5 additions & 6 deletions src/lib/exclude-operational-branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const mainBranches =
/^(\d{4}-\d{2}-\d{2} )?(main|master|production|demo|website|development)$/;

const excludeOperationalBranches = async (branches: string[]) => {
return branches.filter(
(branch) =>
!branch.match(
/^(\d{4}-\d{2}-\d{2} )?(main|master|production|demo|website|development)$/
)
);
return branches.filter((branch) => !mainBranches.exec(branch));
};

export { excludeOperationalBranches };
8 changes: 4 additions & 4 deletions src/lib/from-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import type { Input, Item } from './types';

const SSH_URL_PATTERN =
/^(?<protocol>ssh:\/\/)?([a-zA-Z\d]+)@(?<host>[a-zA-Z\d.]+(:\d+)?)([/:])(?<namespace>[a-zA-Z\d-_]+)\/(?<slug>[a-zA-Z\d-_.]+)\.git$/;
/^(ssh:\/\/)?([a-zA-Z\d]+)@(?<host>[a-zA-Z\d.]+(:\d+)?)([/:])(?<namespace>[a-zA-Z\d-_]+)\/(?<slug>[a-zA-Z\d-_.]+)\.git$/;
const HTTPS_URL_PATTERN =
/^(?<protocol>https:\/\/)(?<host>[a-zA-Z\d.]+)\/(?<namespace>[a-zA-Z\d-_]+)\/(?<slug>[a-zA-Z\d-_.]+)\.git$/;
/^(https:\/\/)(?<host>[a-zA-Z\d.]+)\/(?<namespace>[a-zA-Z\d-_]+)\/(?<slug>[a-zA-Z\d-_.]+)\.git$/;

export const fromInput = (input: Input): Item | undefined => {
const { urlConnection, workspace } = input;

const matchesSSh = urlConnection.match(SSH_URL_PATTERN);
const matchesHttps = urlConnection.match(HTTPS_URL_PATTERN);
const matchesSSh = SSH_URL_PATTERN.exec(urlConnection);
const matchesHttps = HTTPS_URL_PATTERN.exec(urlConnection);

const urlMatch = matchesSSh || matchesHttps;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/link-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const toMap = (searchParams: URLSearchParams) => {
};

export const linkParser = (link: string): Link | undefined => {
const matcher = link.trim().match(LINK_PATTERN);
const matcher = LINK_PATTERN.exec(link.trim());

if (!matcher) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/
export * from './clone-item-task';
export * from './exec-item-task';
export * from './sync-item-task';

0 comments on commit a020ceb

Please sign in to comment.