from fedmsg.meta.base import BaseProcessor


class AnnounceProcessor(BaseProcessor):
    __name__ = "announce"
    __description__ = "Official Fedora Announcements"
    __link__ = "http://fedoraproject.org/"
    __docs__ = "http://fedoraproject.org/"
    __obj__ = "Announcements"

    def subtitle(self, msg, **config):
        return msg['msg']['message']

    def link(self, msg, **config):
        return msg['msg']['link']

    def usernames(self, msg, **config):
        return set([msg['username']])

from fedmsg.meta.base import BaseProcessor


class AnnounceProcessor(BaseProcessor):
    __name__ = "announce"
    __description__ = "Official Fedora Announcements"
    __link__ = "http://fedoraproject.org/"
    __docs__ = "http://fedoraproject.org/"
    __obj__ = "Announcements"

    def subtitle(self, msg, **config):
        return msg['msg']['message']

    def link(self, msg, **config):
        return msg['msg']['link']

    def usernames(self, msg, **config):
        users = set()
        if 'username' in msg:
            users.update(set([msg['username']]))
        return users

Handle the situation where in old message the 'username' key does not exists
Handle the situation where in old message the 'username' key does not exists

With this commit processing an old message with fedmsg_meta will not break
if that old message does not have the 'username' key.

  from fedmsg.meta.base import BaseProcessor
  
  
  class AnnounceProcessor(BaseProcessor):
      __name__ = "announce"
      __description__ = "Official Fedora Announcements"
      __link__ = "http://fedoraproject.org/"
      __docs__ = "http://fedoraproject.org/"
      __obj__ = "Announcements"
  
      def subtitle(self, msg, **config):
          return msg['msg']['message']
  
      def link(self, msg, **config):
          return msg['msg']['link']
  
      def usernames(self, msg, **config):
+         users = set()
+         if 'username' in msg:
-         return set([msg['username']])
+             users.update(set([msg['username']]))
+         return users
  
Handle the situation where in old message the 'username' key does not exists
## Code Before:
from fedmsg.meta.base import BaseProcessor


class AnnounceProcessor(BaseProcessor):
    __name__ = "announce"
    __description__ = "Official Fedora Announcements"
    __link__ = "http://fedoraproject.org/"
    __docs__ = "http://fedoraproject.org/"
    __obj__ = "Announcements"

    def subtitle(self, msg, **config):
        return msg['msg']['message']

    def link(self, msg, **config):
        return msg['msg']['link']

    def usernames(self, msg, **config):
        return set([msg['username']])

## Instruction:
Handle the situation where in old message the 'username' key does not exists
## Code After:
from fedmsg.meta.base import BaseProcessor


class AnnounceProcessor(BaseProcessor):
    __name__ = "announce"
    __description__ = "Official Fedora Announcements"
    __link__ = "http://fedoraproject.org/"
    __docs__ = "http://fedoraproject.org/"
    __obj__ = "Announcements"

    def subtitle(self, msg, **config):
        return msg['msg']['message']

    def link(self, msg, **config):
        return msg['msg']['link']

    def usernames(self, msg, **config):
        users = set()
        if 'username' in msg:
            users.update(set([msg['username']]))
        return users
