Skip to content

Commit

Permalink
use APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabio committed Jul 29, 2024
1 parent f14352f commit eee108b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion _layouts/software-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ <h2>
<div class="col-7 col-sm-7 col-md-3">
<p>
<span class="label">Stato publiccode.yml</span>
<publiccode-badge repo="{{ page.publiccode.url | escape }}"></publiccode-badge>
<publiccode-badge id="{{ page.id }}"></publiccode-badge>
<p>
</div>

Expand Down
19 changes: 8 additions & 11 deletions assets/js/components/PubliccodeBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,30 @@ const useStyle = createUseStyles({
},
});

export const PubliccodeBadge = React.memo(({ repo }) => {
export const PubliccodeBadge = React.memo(({ id }) => {

Check failure on line 26 in assets/js/components/PubliccodeBadge.js

View workflow job for this annotation

GitHub Actions / test

'id' is defined but never used
const [publiccodeState, setPubliccodeState] = useState('loading');

const classes = useStyle(publiccodeState)

useEffect(async () => {
const res = await fetch(logUrl);

if (res.status >= 200 || res.status <= 299) {
const data = await res.json();
const good = data.find(entry => entry?.message?.includes('activity index in the last'));
const good = data[0]?.message.includes('GOOD publiccode.yml');

setPubliccodeState(good ? 'good' : 'error');
} else {
setPubliccodeState('error');
}
});
}, [logUrl]);

const repoPath = repo.replaceAll(/^(.+):\/\/|.git$/ig, '');
const logUrl = `https://crawler.developers.italia.it/${repoPath}/log.json`
const logUrl = `https://api.developers.italia.it/v1/software/${softwareId}/logs`

return (
<>
<div className="lead">
<span className={`badge badge-${stateClass[publiccodeState]}`}>
{publiccodeState === 'loading' && <Spinner />}
{publiccodeState !== 'loading' && publiccodeState }
{publiccodeState !== 'loading' && <Spinner />}
{publiccodeState !== 'loading' && publiccodeState}
</span>
</div>

Expand All @@ -59,14 +56,14 @@ export const PubliccodeBadge = React.memo(({ repo }) => {
target="_blank"
aria-label="Log file of the latest publiccode.yml crawling"
>
(JSON log)
(log)
</a>
</>
);
});

PubliccodeBadge.propTypes = {
repo: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
};

PubliccodeBadge.displayName = 'PubliccodeBadge';

0 comments on commit eee108b

Please sign in to comment.