Skip to content

Commit

Permalink
Merge pull request #113 from artem-solovev/release/18
Browse files Browse the repository at this point in the history
Release/18
  • Loading branch information
kas-elvirov authored Feb 15, 2021
2 parents 3fe2a10 + 2405b2d commit 2175f8c
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APP_VERSION=8.2.20
APP_VERSION=8.2.46
PAYPAL_URL=https://www.paypal.me/ArtemSolovev
OPENCOLLECTIVE_URL=https://opencollective.com/artem-solovev
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '17 21 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ___

## History
### Version:
- current: 8.2.19 ( 2020, 12 july )
- current: 8.2.46 ( 2021, 15 february )
- initial: 2.0.1 ( 2017, 12 february )

I made this program in the Russian Army while I was on duty. I was coding as fast as i could )))
Expand Down
11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Security Policy

## Supported Versions

Any, latest stable versions

## Reporting a Vulnerability

You can report a security related bug in the [GitHub bug tracker](https://github.com/artem-solovev/gloc/issues) or by [email]([email protected]).

All information will be made public. We do not withhold information from users because they need accurate information to access risk and place controls to remediate the risk.
16 changes: 8 additions & 8 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
"message": "Speichern"
},
"optionsCreateToken": {
"message": "Token erstellen"
"message": "Zugriffstoken erstellen"
},
"optionsTokenMustbeString": {
"message": "Zugriffstoken sollte ein String sein, z.B:"
},
"optionsTokenWrongLength": {
"message": "Access Token length appears wrong!"
"message": "Die Länge des Zugriffstokens scheint falsch zu sein!"
},
"optionsTokenWalid": {
"message": "Token ist gültig."
"message": "Zugriffstoken ist gültig."
},
"optionsSaved": {
"message": "Optionen gespeichert!"
Expand All @@ -57,16 +57,16 @@
"message": "Zählt die Anzahl der Codezeilen eines Projektes aus:"
},
"indexProjectPage": {
"message": "projekdetailseite"
"message": "Projekdetailseite"
},
"indexUserPage": {
"message": "benutzerseite"
"message": "Benutzerseite"
},
"indexSearchPage": {
"message": "suchergebnissseite"
"message": "Suchergebnissseite"
},
"indexTrandingPage": {
"message": "trendseite"
"message": "Trendseite"
},
"indexEtc": {
"message": "etc."
Expand All @@ -84,6 +84,6 @@
"message": "Durch Erweiterungen:"
},
"lines": {
"message": "linien"
"message": "Zeilen"
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"short_name": "__MSG_shortName__",
"author": "__MSG_author__",
"description": "__MSG_description__",
"version": "8.2.20",
"version": "8.2.46",
"browser_action": {
"default_icon": "img/icon128.png",
"default_popup": "index.html",
Expand Down
26 changes: 10 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloc",
"version": "8.2.20",
"version": "8.2.46",
"description": "Extension counts the number of lines of code in GitHub pages.",
"author": "Artem Solovev",
"license": "GPL-2.0",
Expand All @@ -20,8 +20,8 @@
],
"main": "index.js",
"scripts": {
"pack:dev": "webpack --config webpack.config.prod",
"pack:prod": "webpack --config webpack.config.dev",
"pack:prod": "webpack --config webpack.config.prod",
"pack:dev": "webpack --config webpack.config.dev",
"zip": "grunt",
"build:prod": "webpack --config webpack.config.prod && grunt",
"build:dev": "webpack --config webpack.config.dev && grunt",
Expand Down
1 change: 1 addition & 0 deletions src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export const MESSAGE_IDS = {
};

export const DEFAULT_OUTPUT = 'Stat is unavailable';
export const LOADING_OUTPUT = 'Loading...';
1 change: 1 addition & 0 deletions src/theme/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const colors = {
mainGreen: '#09af00',
mainPink: '#b1006a',
mainWhite: '#fff',
mainPurple: '#9f00b1',

// https://material.io/design/color/the-color-system.html#tools-for-picking-colors
/* GREY */
Expand Down
6 changes: 5 additions & 1 deletion src/utils/getBgColorForLoc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { DEFAULT_OUTPUT } from '../consts/index';
import { DEFAULT_OUTPUT, LOADING_OUTPUT } from '../consts/index';
import { colors } from '../theme/colors';

export const getBgColorForLoc = (lines: string): string => {
if (lines === DEFAULT_OUTPUT) {
return colors.mainPink;
}

if (lines === LOADING_OUTPUT) {
return colors.mainPurple;
}

return colors.mainGreen;
};
31 changes: 22 additions & 9 deletions src/utils/renderLocs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TRIES_DEFAULT } from '../consts/index';
import { LOADING_OUTPUT, TRIES_DEFAULT } from '../consts/index';

import { formatOutput } from './formatOutput';
import { requestLoc } from './requestLoc';
Expand All @@ -7,18 +7,31 @@ import { InitialData } from '../types';

export const renderLocs = (linksData: InitialData, token: string) => {
linksData.links.map((anchor: HTMLAnchorElement, index) => {
const reponame = anchor.getAttribute('href');
const repoName = anchor.getAttribute('href');

const placeToInsert = linksData.linksToInsert[index] || anchor;

if (reponame) {
requestLoc(reponame, TRIES_DEFAULT, token)
.then(loc => renderLoc(placeToInsert, formatOutput(loc)))
.catch(err => console.error(`Error by setting LOC for ${reponame}`, err));
if (repoName) {
const renderLoc = makeRenderFunc(placeToInsert);

renderLoc(LOADING_OUTPUT);


requestLoc(repoName, TRIES_DEFAULT, token)
.then(loc => renderLoc(formatOutput(loc)))
.catch(err => console.error(`Error by setting LOC for ${repoName}`, err));
}
});
};

const renderLoc = (anchor: HTMLAnchorElement, loc: string) => {
anchor.innerHTML += renderBadge(loc);
};
/**
* Creates a function to render LOC badges.
* The initial inner HTML of the anchor element is saved and reset upon updating the badge.
* @param anchor HTML Element to add LOC badges to
*/
const makeRenderFunc = (anchor: HTMLAnchorElement) => {
const startInnerHTML = anchor.innerHTML;
return (loc: string) => {
anchor.innerHTML = startInnerHTML + renderBadge(loc);
};
};
56 changes: 47 additions & 9 deletions src/utils/requestLoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import { isEmpty } from './isEmpty';
- https://developer.github.com
/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters
*/
export const requestLoc = (reponame: string, tries: number, token: string): Promise<number | void | null> => {
if (tries === 0) {
return Promise.reject('Repo: ' + reponame + '; Too many requests to API !');
}

const url = getApiUrl(reponame);
function makeRequest(repoName: string, token: string): Promise<Response> {
const url = getApiUrl(repoName);
const options: RequestInit | undefined = {
method: 'GET',
};
Expand All @@ -26,22 +23,63 @@ export const requestLoc = (reponame: string, tries: number, token: string): Prom
};
}

return fetch(url, options)
return fetch(url, options);
}

export const requestLoc = (repoName: string, tries: number, token: string): Promise<number | void | null> => {
if (tries === 0) {
return Promise.reject(`Repo: ${repoName}; Too many requests to API !`);
}

return makeRequest(repoName, token)
.then(async response => {
// A response of 202 indicates that stats are still being collected.
// After waiting for a couple seconds, the stats are usually available.
if (response.status === 202) {
let sleepTime = 1000;
let status = 202;
let tries = 4;
while (tries > 0) {
// sleep for some time
await new Promise(resolve => window.setTimeout(resolve, sleepTime));
const resp = await makeRequest(repoName, token);
status = resp.status;

// got a 200 or an error
if (status !== 202) {
return resp;
}

// exponentially increase wait time
sleepTime *= 2;
tries--;
}
} else if (response.status === 200) {
return response;
}
return Promise.reject();
})
.then(response => response.json())
.then((stat: CodeFrequency) => {
if (!isEmpty(stat)) {
return calculateLoc(stat);
}

console.error(`Error by calculating LOC for ${reponame}. Incoming stat -->`, stat);
console.error(`Error by calculating LOC for ${repoName}. Incoming stat -->`, stat);

return null;
})
.catch((err: GithubError) => {
// this occurs when we retry after a 202 and still don't get a 200 response
if (err === undefined) {
console.error(`Error by getting stat for ${repoName}.`);
return;
}

if (err.message) {
console.error(`Error by getting stat for ${reponame}. Response -->`, err);
console.error(`Error by getting stat for ${repoName}. Response -->`, err);
}

requestLoc(reponame, tries - 1, token);
requestLoc(repoName, tries - 1, token);
});
};

0 comments on commit 2175f8c

Please sign in to comment.