OSD 600 Lab5


In this week's lab, we are going to refactor our code of release 0.1. Since we have learned some git history commands this week, we are going to practice the commands git rebase, git commit --amend to rewrite the history of the previews commits after the refactoring.

Refactoring my release 0.1

The first change

I rewrote the code about sending asynchronous requests. I was using sync-request dependency for sending the asynchronous request. It makes the request super slow since they were waiting for the preview request to finish. I removed the sync-request dependency and installed the request dependency, then I created my checkUrls() function that returns an array of promise(Promiss.all). 

const checkUrls = (urlsjsonstatus=> {
    return Promise.all(
        urls.map((url=> sendRequest(urljsonstatus))
    );
};

The second change 

I changed my readFile() function can readFile asynchronously. I just simply make the function return a promise. In the main file, I put everything into an async function run(), then add the keyword await to readFile();

The third change

I created a class named MyFile and put all the File related functions and those properties (status, json, filter) into it.

class MyFile {

    constructor() {
        this.status = 'all';
        this.json = false;
        this.filteredUrl = null;
    }

    readFile (fileString = this.fileStringjson = this.jsonstatus = this.status
filteredUrl = this.filteredUrl

Before

            let status = "all";
            let json = false;
            let i = 3;
            let filter = null;

            if (argv.goodstatus = "good";
            else if (argv.badstatus = "bad";
            else if (argv.json || argv.jjson = true;
            else {
                status = "all";
                i = 2;
            }

            if (argv.ureadUrl(process.argv[3]);

            for (ii < process.argv.lengthi++) {
                await readFile(process.argv[i], jsonstatusfilter);
            }

After    

        else {
            let myFile = new MyFile();
            let index = 3;
            if (argv.goodmyFile.status = 'good';
            else if (argv.badmyFile.status = "bad";
            else if (argv.all);
            else if (argv.json || argv.jmyFile.json = true;
            else index = 2;
            if (argv.umyFile.readUrl(process.argv[3]);
            for (i = indexi < process.argv.lengthi++) {
                await myFile.readFile(process.argv[i]);
            }




Practice git commands

firstly, i ran "git rebase -i HEAD~7" to edit my 7 previews commit, then I squashed all 2-7 commits. After
that, I practiced git commit --amend to change my commit message. Since I completely changed my
commit history, I cannot do a faster-forward push. I used "git push origin master --force" commit to
pushing my new commit to my Github

Comments

Popular posts from this blog

My PR for release 0.3 External Project

OSD600 Lab8

My OSD600 release 0.1