home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.83k stars 28.95k forks source link

The Great Migration - Tools update #22201

Closed balloob closed 5 years ago

balloob commented 5 years ago

With the great migration coming to an end, it's time to track the final tasks and make sure they are done before 0.91.

Swamp-Ig commented 5 years ago
MartinHjelmare commented 5 years ago

The documentation update is a separate discussion which should probably be done in that repo. Migrating the docs for an integration from many platform pages into the component page is under way. But it doesn't scale for large integrations that need details for their platforms. See eg https://github.com/home-assistant/home-assistant.io/pull/8593.

balloob commented 5 years ago

It won't be necessary to merge all the docs, as long as we just treat the component as an entrypoint to the docs for that integration. The page itself will actually show its platforms.

robbiet480 commented 5 years ago

don't laugh at my janky modern js skills

script to update component labels:

const Octokit = require('@octokit/rest')
const octokit = new Octokit({
  auth: 'token TOKEN_HERE'
});

const options = octokit.issues.listLabelsForRepo.endpoint.merge({
  owner: 'home-assistant',
  repo: 'home-assistant',
  per_page: 100,
})
octokit.paginate(options)
  .then(data => {
    data.forEach(existing_label => {
      if(existing_label.name.indexOf('component: ') !== -1) {
        console.log('rename', existing_label.name, 'to', existing_label.name.replace('component: ', 'integration: '));
        octokit.issues.updateLabel({
          owner: 'home-assistant',
          repo: 'home-assistant',
          current_name: existing_label.name,
          name: existing_label.name.replace('component: ', 'integration: '),
        }).then(updated_label => {
          console.log('Updated', existing_label.name, 'to', updated_label.name);
        })
      }
    });
  });

script to update platform labels:

const Octokit = require('@octokit/rest')
const octokit = new Octokit({
  auth: 'token TOKEN_HERE'
});

const options = octokit.pulls.list.endpoint.merge({
  owner: 'home-assistant',
  repo: 'home-assistant',
  state: 'open',
  per_page: 100,
})
octokit.paginate(options).then(data => {
  data.forEach(pull_request => {
    var needsLabelUpdate = false;
    var newLabels = [];
    pull_request.labels.forEach(label => {
      if(label.name.indexOf('platform: ') !== -1) {
        needsLabelUpdate = true;
        var splitName = label.name.split('.');
        label.name = 'integration: '+splitName[1];
      }
      newLabels.push(label.name);
    });
    if(needsLabelUpdate) {
      console.log('newLabels', pull_request.number, newLabels);
      octokit.issues.update({
        owner: 'home-assistant',
        repo: 'home-assistant',
        number: pull_request.number,
        labels: newLabels,
      }).then(({data, headers, status}) => {
        console.log('Updated labels for PR', data.number);
      })
    }
  });
});
robbiet480 commented 5 years ago

Here's one related helpful script to get a detailed breakdown of label usage in a repo. It output these stats.

const graphql = require('@octokit/graphql').defaults({
  headers: {
    authorization: `token TOKEN_HERE`
  }
})

async function getCounts(owner, repoName, labelMap, cursor){
  if(!labelMap) labelMap = {};
  const labelsWithCursor = await graphql(`query labelsWithCursor($owner: String!, $repoName: String! $after: String = null) {
      repository(owner:$owner, name:$repoName) {
        labels(first: 100, after:$after) {
          edges {
            cursor
            node {
              name
              openIssues: issues(states: [OPEN]) {
                totalCount
              }
              closedIssues: issues(states: [CLOSED]) {
                totalCount
              }
              openPRs: pullRequests(states: [OPEN]) {
                totalCount
              }
              mergedPRs: pullRequests(states: [MERGED]) {
                totalCount
              }
              closedPRs: pullRequests(states: [CLOSED]) {
                totalCount
              }
            }
          }
        }
      }
    }`, {
      owner: owner,
      repoName: repoName,
      after: cursor
    });

  labelsWithCursor.repository.labels.edges.forEach(edge => {
    if(!labelMap[edge.node.name]) {
      labelMap[edge.node.name] = {
        'Open Issues': edge.node.openIssues.totalCount,
        'Closed Issues': edge.node.closedIssues.totalCount,
        'Open Pull Requests': edge.node.openPRs.totalCount,
        'Merged Pull Requests': edge.node.mergedPRs.totalCount,
        'Closed Pull Requests': edge.node.closedPRs.totalCount
      };
    }

    labelMap[edge.node.name]['Open Issues']          = labelMap[edge.node.name]['Open Issues']          + edge.node.openIssues.totalCount;
    labelMap[edge.node.name]['Closed Issues']        = labelMap[edge.node.name]['Closed Issues']        + edge.node.closedIssues.totalCount;
    labelMap[edge.node.name]['Open Pull Requests']   = labelMap[edge.node.name]['Open Pull Requests']   + edge.node.openPRs.totalCount;
    labelMap[edge.node.name]['Merged Pull Requests'] = labelMap[edge.node.name]['Merged Pull Requests'] + edge.node.mergedPRs.totalCount;
    labelMap[edge.node.name]['Closed Pull Requests'] = labelMap[edge.node.name]['Closed Pull Requests'] + edge.node.closedPRs.totalCount;
  });

  var lastElm = labelsWithCursor.repository.labels.edges.pop();

  if(!lastElm) {
    return labelMap;
  }

  return await getCounts(owner, repoName, labelMap, lastElm.cursor);
};

const start = async function(){
  const labelMap = await getCounts("home-assistant", "home-assistant");
  console.log(JSON.stringify(labelMap));
}

start();
robbiet480 commented 5 years ago

List of broken labels that need fixing:

Choose one to keep:

robbiet480 commented 5 years ago

Hopefully final list of labels after migration is completed, please point out any that should be cleaned up (or even better, do it yourself):

Swamp-Ig commented 5 years ago
robbiet480 commented 5 years ago

Implemented all of @Swamp-Ig's suggestions.

robbiet480 commented 5 years ago

Deletion of platform: labels complete!

robbiet480 commented 5 years ago

Thanks all but mostly me!