Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:

push:
name: 'push'
name: 'Test and Deploy'
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.label.name == 'safe-to-stage'

Expand Down Expand Up @@ -39,6 +39,10 @@ jobs:
with:
cmd: build

- uses: borales/actions-yarn@v2.3.0
with:
cmd: test

# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
working-directory: terraform
Expand Down
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ Say a users query is `fly gh Apollorion manifests.io`
The example logic above will match `gh`, split `Apollorion manifests.io` into `$1` = `Apollorion` and `$2` = `manifests.io`.
The logic defined in `extension/flights.ts` for `gh` is `https://github.com/$1/$2` which resolves to `https://github.com/Apollorion/manifests.io`.

If your logical flight doesnt need to be very smart you can simply add the flight name (`gh` in the above example) to the`logicalFlights` const in `extension/background.ts`.
If your logical flight doesnt need to be very smart you can simply add the flight name (`gh` in the above example) to the`logicalFlights` const in `extension/main.ts`.
The extension will "just work" if you expect users to always type the full query in the extension.
As an example, the `aws` flight automatically builds the correct query without any special logic because it expects the user to type the full query every time.

If you logical flight does need some custom logic, you can build that into `extension/background.ts`. I'd suggest using `gh` as an example.
If you logical flight does need some custom logic, you can build that into `extension/main.ts`. I'd suggest using `gh` as an example.


# Alfred
Expand Down
128 changes: 1 addition & 127 deletions extension/background.ts
Original file line number Diff line number Diff line change
@@ -1,130 +1,4 @@
import {
FlightType,
Flight
} from "./types.js";

import {
getFlightFromQuery,
setCalled,
unsetCalled,
getLocalStorage,
redirect,
checkRepoFlights, getNewFlightResponseSynchronous
} from "./helpers.js";

const repoFlightResponsePromise = checkRepoFlights();

async function main() {
// @ts-ignore
chrome.omnibox.onInputEntered.addListener(async (text, OnInputEnteredDisposition) => {
const query = text.split(" ");
if(query[0] === "set"){
await setCalled(query);
} else if (query[0] === "unset") {
await unsetCalled(query);
} else {
const repoFlightResponse = await repoFlightResponsePromise;
const flight = await getFlightFromQuery(query, repoFlightResponse);
await handleFlight(flight);
}
});
}

async function handleStandardFlight(flight: Flight){
const repoFlightResponse = await repoFlightResponsePromise;
let newFlights = getNewFlightResponseSynchronous(repoFlightResponse);
const newStandardFlights = newFlights.standard;

for(let key in newStandardFlights){
for(let value of newStandardFlights[key]){
if(value === flight.identifier){
return await redirect(`Following Link`, key);
}
}
}

await redirect("Not a standard flight", "https://github.com/Apollorion/fly");
}

async function handleFlight(flight: Flight){
const repoFlightResponse = await repoFlightResponsePromise;
let newFlights = getNewFlightResponseSynchronous(repoFlightResponse);
const newLogicalFlights = newFlights.logical;

if(flight.type === FlightType.LOGICAL && flight.values !== undefined) {
if (flight.identifier in newLogicalFlights) {
let flightDetails = newLogicalFlights[flight.identifier];
let logic = flightDetails["logic"];

// Regex that match everything inside ${}
let regex = /\${([^}]*)}/g;
let matches = logic.match(regex);

if(matches === null) {
console.log("Matches is null");

// If the length of matches and the flight values are the same
// The user wants to supply all the values
} else if (matches.length === flight.values.length) {
let i = 0;
for(let match of matches){
const value = flight.values[i];
if(value !== undefined) {
logic = logic.replace(match, value);
i++;
}
}

} else {
for(let match of matches){
try {
const matchNoBrackets = match.replace("${", "").replace("}", "");
const value = await getLocalStorage(matchNoBrackets);
if(value !== undefined) {
logic = logic.replace(match, value);

// Remove the item from the array, so we can replace using the values of the flight later
const index = matches.indexOf(match);
if (index > -1) {
matches.splice(index, 1); // 2nd parameter means remove one item only
}
}
} catch {
console.log("Could not find value for: " + match);
}
}

// If there are still matches left, we will treat them as positional variables
let i = 0;
for(let match of matches){
const value = flight.values[i];
if(value !== undefined) {
logic = logic.replace(match, value);
i++;
}
}
}

if(logic.includes("${") && logic.includes("}")){
if(flight.values.length === 0){
if(flight.override !== undefined) {
return await redirect("override flight", flight.override);
} else {
return await redirect("Incorrect Length", "https://github.com/Apollorion/fly/blob/main/help/logical-logicalFlights.md#incorrect-length");
}
}
} else {
return await redirect("Following Link", logic);
}

} else {
return await redirect("Logic Not Found", "https://github.com/Apollorion/fly/blob/main/help/logical-logicalFlights.md#logic-not-found");
}
} else {
return await handleStandardFlight(flight);
}

}
import { main } from './main.js';

main().then(()=>{
console.log("Finished");
Expand Down
Loading